<?php

namespace App\Classes\Modules\Documents\ControllersLogic;

use App\Classes\Modules\Documents\Standards\Rules\CanApproveDocument;
use App\Http\Resources\DocumentResource;

use App\Classes\General\Abstracts\AbstractControllerLogic;

use App\Classes\Modules\Documents\Services\FetchesDocument;

use App\Classes\Modules\Documents\Services\ApprovesDocument;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ApproveDocumentLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Approve Document',
            'message' => 'You have successfully approved the Document'
        ];
    }

    /** @var CanApproveDocument*/
    private $canApproveDocument;

    /** @var ApprovesDocument */
    private $approvesDocument;

    /** @var FetchesDocument */
    private $fetchesDocument;


    /**
     * RejectDocumentLogic constructor.
     * @param CanApproveDocument $canApproveDocument
     * @param ApprovesDocument $approvesDocument
     * @param FetchesDocument $fetchesDocument
     */
    public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, FetchesDocument $fetchesDocument)
    {
        $this->canApproveDocument = $canApproveDocument;
        $this->approvesDocument = $approvesDocument;
        $this->fetchesDocument = $fetchesDocument;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function logic(Request $request) : JsonResponse
    {

        $document = $this->fetchesDocument->execute(['id' => $request->route('id')]);

        $this->canApproveDocument->passes();

        $document_query = $this->approvesDocument->execute($document);

        return $this->resourceResponse(new DocumentResource($document_query));

    }

}