<?php

namespace App\Classes\Modules\Currencies\ControllersLogic;

use App\Http\Resources\CurrencyResource;

use App\Classes\General\Abstracts\AbstractControllerLogic;

use App\Classes\Modules\Currencies\Services\FetchesCurrency;

use App\Classes\Modules\Currencies\Standards\Rules\CanDeleteCurrency;
use App\Classes\Modules\Currencies\Services\DeletesCurrency;

use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class DeleteCurrencyLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Delete Currency',
            'message' => 'You have successfully deleted the Currency'
        ];
    }

    /** @var CanDeleteCurrency */
    private $canDeleteCurrency;

    /** @var DeletesCurrency */
    private $deletesCurrency;

    /** @var FetchesCurrency */
    private $fetchesCurrency;


    /**
     * DeleteCurrencyLogic constructor.
     * @param CanDeleteCurrency $canDeleteCurrency
     * @param DeletesCurrency $deletesCurrency
     * @param FetchesCurrency $fetchesCurrency
     */
    public function __construct(
        CanDeleteCurrency $canDeleteCurrency, 
        DeletesCurrency $deletesCurrency, 
        FetchesCurrency $fetchesCurrency
    )
    {
        $this->canDeleteCurrency = $canDeleteCurrency;
        $this->deletesCurrency = $deletesCurrency;
        $this->fetchesCurrency = $fetchesCurrency;
    }

    /**
     * @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->canDeleteCurrency->passes();

        $currency_query = $this->fetchesCurrency->execute(['id' => $request->route('id')]);

        $this->deletesCurrency->execute($currency_query);

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

}