<?php

namespace App\Classes\Modules\Milestones\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Milestones\Services\ListsMilestones;
use App\Http\Resources\MilestoneResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListMilestonesLogic extends AbstractControllerLogic
{

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


    /** @var ListsMilestones */
    private $listsMilestones;

    /**
     * ListMilestonesLogic constructor.
     * @param ListsMilestones $listsMilestones
     */
    public function __construct(ListsMilestones $listsMilestones)
    {
        $this->listsMilestones = $listsMilestones;
    }

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

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

}
