<?php

namespace AuthStack\OAuth2\Model\Protocol\Response;

use Illuminate\Http\Request;

abstract class AbstractResponse
{
    protected $model = [];

    abstract public function toArray();

    abstract public function receive(Request $request = null);

    /**
     * @param array $model
     * @return self
     */
    public static function fromArray(array $model): self
    {
        $me = new static;

        $me->model = $model;

        return $me;
    }

    /**
     * @param $property
     * @param $value
     * @return self
     */
    protected function setProperty($property, $value): self
    {
        $this->model[$property] = $value;

        return $this;
    }

    /**
     * @param $property
     * @param null $default
     * @return mixed|null
     */
    protected function getProperty($property, $default = null)
    {
        return isset($this->model[$property]) ? $this->model[$property] : $default;
    }

    /**
     * @param array $model
     * @return self
     */
    public function setModel(array $model): self
    {
        $this->model = $model;

        return $this;
    }
}