<?php

namespace App\Classes\Modules\Companies\ControllersLogic;

use App\Http\Resources\CompanyResource;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Services\UpdatesCompanyStatus;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UpdateCompanyStatusLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Update Company Account Status',
            'message' => 'You have successfully updated the Company Account Status'
        ];
    }

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

    /** @var UpdatesCompanyStatus */
    private $updatesCompanyStatus;

    /**
     * UpdateCompanyStatusLogic constructor.
     * @param FetchesCompany $fetchesCompany
     * @param UpdatesCompanyStatus $updatesCompanyStatus
     */
    public function __construct(
        FetchesCompany $fetchesCompany,
        UpdatesCompanyStatus $updatesCompanyStatus
    )
    {
        $this->fetchesCompany = $fetchesCompany;
        $this->updatesCompanyStatus = $updatesCompanyStatus;
    }

    /**
     * @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
    {
        $company = $this->fetchesCompany->execute(['id' => $request->route('id')]);

        $company_query = $this->updatesCompanyStatus->execute($company, $request->input('status'));

        return $this->resourceResponse(new CompanyResource($company_query));

    }

}