<?php

namespace App\Classes\Modules\Documents\ControllersLogic;

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

use App\Classes\General\Abstracts\AbstractControllerLogic;

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

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

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

use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionProcessor;


class DeleteDocumentLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Deleted Document',
            'message' => 'You have successfully deleted a document'
        ];
    }

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

    /** @var DeletesDocument */
    private $deletesDocument;

    /** @var CanDeleteDocument */
    private $canDeleteDocument;

    /**
     * DeleteDocumentLogic constructor.
     * @param FetchesDocument $fetchesDocument
     * @param DeletesDocument $deletesDocument
     * @param CanDeleteDocument $canDeleteDocument
     */
    public function __construct(FetchesDocument $fetchesDocument, DeletesDocument $deletesDocument, CanDeleteDocument $canDeleteDocument)
    {
        $this->fetchesDocument = $fetchesDocument;
        $this->deletesDocument = $deletesDocument;
        $this->canDeleteDocument = $canDeleteDocument;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function logic(Request $request) : JsonResponse
    {
        $document = $this->fetchesDocument->execute(['id' => $request->route('id')]);

        $this->canDeleteDocument->passes();
        
        $this->deletesDocument->execute($document);

        return $this->response([]);
    }
}