<?php

namespace App\Classes\Modules\ServiceTypes\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceType;
use App\Classes\Modules\ServiceTypes\Services\UpdatesServiceTypeStatus;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UpdateServiceTypeStatusLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Update Service Type',
            'message' => 'You have successfully updated a Service Type status'
        ];
    }

    /** @var FetchesServiceType */
    private $fetchesServiceType;

    /** @var UpdatesServiceTypeStatus */
    private $updatesServiceTypeStatus;

    /**
     * UpdateServiceTypeStatusLogic constructor.
     * @param FetchesServiceType $fetchesServiceType
     * @param UpdatesServiceTypeStatus $updatesServiceTypeStatus
     */
    public function __construct(FetchesServiceType $fetchesServiceType, UpdatesServiceTypeStatus $updatesServiceTypeStatus)
    {
        $this->fetchesServiceType = $fetchesServiceType;
        $this->updatesServiceTypeStatus = $updatesServiceTypeStatus;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     */
    public function logic(Request $request) : JsonResponse
    {


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

        $this->updatesServiceTypeStatus->execute($query, $request->route('status') === 'active' ? ApprovalStatus::APPROVED : ApprovalStatus::SUSPENDED);

        return $this->response([]);

    }

}