<?php

namespace App\Classes\Modules\Vouchers\ControllersLogic;

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

class ListUserVouchersLogic extends AbstractControllerLogic
{
    /**
     * ListUserVouchersLogic constructor.
     * @param ListsUserRewards $listsUserRewards
     */
    public function __construct(ListsUserRewards $listsUserRewards)
    {
        $this->listsUserRewards = $listsUserRewards;
    }

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

    /** @var ListsUserRewards */
    private $listsUserRewards;

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

}
