<?php

namespace App\Classes\Modules\Segments\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Segments\Services\ListsSegments;
use App\Http\Resources\SegmentResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListSegmentLogic extends AbstractControllerLogic
{

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


    /** @var ListsSegments */
    private $listsSegments;

    /**
     * ListSegmentLogic constructor.
     * @param ListsSegments $listsSegments
     */
    public function __construct(ListsSegments $listsSegments)
    {
        $this->listsSegments = $listsSegments;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function logic(Request $request) : JsonResponse
    {

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

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

    }

}