<?php

namespace App\Classes\Modules\Documents\ControllersLogic;

use App\Classes\Modules\Documents\Services\RejectsDocument;
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 Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class RejectDocumentLogic extends AbstractControllerLogic
{

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

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

    /** @var RejectsDocument */
    private $rejectsDocument;

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

    /**
     * RejectDocumentLogic constructor.
     * @param CanApproveDocument $canApproveDocument
     * @param RejectsDocument $rejectsDocument
     * @param FetchesDocument $fetchesDocument
     */
    public function __construct(CanApproveDocument $canApproveDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument)
    {
        $this->canApproveDocument = $canApproveDocument;
        $this->rejectsDocument = $rejectsDocument;
        $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->rejectsDocument->execute($document);

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

    }

}