<?php

namespace App\Classes\Modules\Banks\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Banks\Services\ListsBanks;
use App\Classes\Modules\Banks\Standards\Rules\CanListBanks;
use App\Http\Resources\BankResource;
use App\Http\Resources\CompanyResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListBanksLogic extends AbstractControllerLogic
{

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

    /** @var CanListBanks */
    private $canListBanks;

    /** @var ListsBanks */
    private $listsBanks;

    /**
     * ListBanksLogic constructor.
     * @param CanListBanks $canListBanks
     * @param ListsBanks $listsBanks
     */
    public function __construct(CanListBanks $canListBanks, ListsBanks $listsBanks)
    {
        $this->canListBanks = $canListBanks;
        $this->listsBanks = $listsBanks;
    }


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

        $banks = $this->listsBanks->execute($this->listsBanks->deserializeFilters($request->input('filters')));

        return $this->collectionResponse(BankResource::collection($banks));

    }

}