<?php

namespace App\Classes\Modules\Currencies\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Currencies\Services\ListsCurrency;
use App\Classes\Modules\Currencies\Standards\Rules\CanListCurrency;
use App\Http\Resources\CurrencyResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListCurrencyLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Retrieved Currency',
            'message' => 'You have successfully retrieved a list of Currency'
        ];
    }

    /** @var CanListCurrency */
    private $canListCurrency;

    /** @var ListsCurrency */
    private $listsCurrency;

    /**
     * ListCurrencyLogic constructor.
     * @param CanListCurrency $canListCurrency
     * @param ListsCurrency $listsCurrency
     */
    public function __construct(CanListCurrency $canListCurrency, ListsCurrency $listsCurrency)
    {
        $this->canListCurrency = $canListCurrency;
        $this->listsCurrency = $listsCurrency;
    }


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

        $query = $this->listsCurrency->execute($this->listsCurrency->deserializeFilters($request->input('filters')));

        return $this->collectionResponse(CurrencyResource::collection($query));

    }

}