<?php

namespace AuthStack\OAuth2\Model\Protocol\Request;


use Illuminate\Http\Request;

abstract class AbstractRequest
{
    protected $model = [
        'response_type' => null,
        'client_id' => null,
        'redirect_uri' => null,
        'scope' => null,
        'state' => null
    ];

    abstract public function toArray(): array;

    abstract public function model(): array;

    /**
     * @param Request|null $request
     * @return self
     */
    abstract public function receive(Request $request = null);

    /**
     * @param string $client_id
     * @return AbstractRequest
     */
    public function setClientID(string $client_id): self
    {
        return $this->setProperty('client_id', $client_id);
    }

    /**
     * @param string $uri
     * @return AbstractRequest
     */
    public function setRedirectUri(string $uri)
    {
        return $this->setProperty('redirect_uri', $uri);
    }

    /**
     * @param string $scope
     * @return AbstractRequest
     */
    public function setScope(string $scope)
    {
        return $this->setProperty('scope', $scope);
    }

    /**
     * @param string $state
     * @return AbstractRequest
     */
    public function setState(string $state)
    {
        return $this->setProperty('state', $state);
    }

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

        return $this;
    }

    /**
     * @param $property
     * @param null $default
     * @return mixed|null
     */
    public 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;
    }
}