<?php

namespace App\Classes\Modules\Rewards\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Rewards\Services\ListsRewards;
use App\Http\Resources\RewardResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListRewardsLogic extends AbstractControllerLogic
{

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


    /** @var ListsRewards */
    private $listsRewards;

    /**
     * ListRewardsLogic constructor.
     * @param ListsRewards $listsRewards
     */
    public function __construct(ListsRewards $listsRewards)
    {
        $this->listsRewards = $listsRewards;
    }

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

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

}
