<?php

namespace App\Classes\Modules\Addresses\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Addresses\Services\ListsAddresses;
use App\Classes\Modules\Addresses\Services\ListsStates;
use App\Classes\Modules\Addresses\Standards\Rules\CanListAddresses;
use App\Http\Resources\AddressResource;
use App\Http\Resources\StateResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListStatesLogic extends AbstractControllerLogic
{

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

    /** @var ListsStates */
    private $listStates;

    /**
     * ListStatesLogic constructor.
     * @param ListsStates $listStates
     */
    public function __construct(ListsStates $listStates)
    {
        $this->listStates = $listStates;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function logic(Request $request) : JsonResponse
    {
        $query = $this->listStates->execute($this->listStates->deserializeFilters($request->input('filters')));

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

    }

}