<?php

namespace App\Classes\Modules\Remarks\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Remarks\Services\DeletesRemark;
use App\Classes\Modules\Remarks\Services\FetchesRemark;
use App\Classes\Modules\Remarks\Standards\Rules\CanDeleteRemark;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

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


    /** @var CanDeleteRemark */
    private $canDeleteRemark;

    /** @var DeletesRemark */
    private $deletesRemark;

    /** @var FetchesRemark */
        private $fetchesRemark;

    /**
     * DeleteRemarkControllersLogic constructor.
     * @param CanDeleteRemark $canDeleteRemark
     * @param DeletesRemark $deletesRemark
     * @param FetchesRemark $fetchesRemark
     */
    public function __construct(CanDeleteRemark $canDeleteRemark, DeletesRemark $deletesRemark, FetchesRemark $fetchesRemark)
    {
        $this->canDeleteRemark = $canDeleteRemark;
        $this->deletesRemark = $deletesRemark;
        $this->fetchesRemark = $fetchesRemark;
    }


    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ErrorException
     */
    public function logic(Request $request) : JsonResponse
    {
        $this->canDeleteRemark->passes();

        $query = $this->fetchesRemark->execute(['id' => $request->route('id')]);

        $this->deletesRemark->execute($query);

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

}
