<?php

namespace App\Classes\Modules\Affiliate\ControllersLogic;

use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Affiliate\Services\ListsAffiliates;
use App\Http\Resources\AffiliateResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

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

    /** @var ListsAffiliates */
    private $listsAffiliates;

    /**
     * @param ListsAffiliates $listsAffiliates
     */
    public function __construct(ListsAffiliates $listsAffiliates)
    {
        $this->listsAffiliates = $listsAffiliates;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     */
    public function logic(Request $request): JsonResponse
    {
        $query = $this->listsAffiliates->execute($this->listsAffiliates->deserializeFilters($request->input('filters')));

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

