<?php

namespace App\Classes\Modules\Companies\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\DeletesCompany;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Standards\Rules\CanDeleteCompany;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

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


    /** @var CanDeleteCompany */
    private $canDeleteCompany;

    /** @var DeletesCompany */
    private $deletesCompany;

    /** @var FetchesCompany */
    private $fetchesCompany;

    /**
     * DeleteCompanyLogic constructor.
     * @param CanDeleteCompany $canDeleteCompany
     * @param DeletesCompany $deletesCompany
     * @param FetchesCompany $fetchesCompany
     */
    public function __construct(CanDeleteCompany $canDeleteCompany, DeletesCompany $deletesCompany, FetchesCompany $fetchesCompany)
    {
        $this->canDeleteCompany = $canDeleteCompany;
        $this->deletesCompany = $deletesCompany;
        $this->fetchesCompany = $fetchesCompany;
    }


    /**
     * @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
    {

        $this->canDeleteCompany->passes();

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

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

        return $this->response([]);

    }

}