<?php

namespace App\Classes\Modules\Addresses\ControllersLogic;


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

class ListStatesLogic extends AbstractControllerLogic
{

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

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

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

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

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

    }

}
