<?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\ListsDistricts;
use App\Classes\Modules\Addresses\Standards\Rules\CanListAddresses;
use App\Http\Resources\AddressResource;
use App\Http\Resources\DistrictResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListDistrictsLogic extends AbstractControllerLogic
{

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

    /** @var ListsDistricts */
    private $listDistricts;

    /**
     * ListDistrictsLogic constructor.
     * @param ListsDistricts $listDistricts
     */
    public function __construct(ListsDistricts $listDistricts)
    {
        $this->listDistricts = $listDistricts;
    }

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

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

    }

}