<?php

namespace App\Classes\Modules\KeyValuePairs\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\KeyValuePairs\Services\ListsKeyValuePairs;
use App\Classes\Modules\KeyValuePairs\Standards\Rules\CanListAiPrompts;
use App\Http\Resources\ChatGPTPromptResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListAiPromptsKVPLogic extends AbstractControllerLogic
{

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

    /** @var CanListAiPrompts */
    private $canListAiPrompts;

    /** @var ListsKeyValuePairs */
    private $listsKeyValuePairs;

    /**
     * ListAiPromptsKVPLogic constructor.
     * @param CanListAiPrompts $canListAiPrompts
     * @param ListsKeyValuePairs $listsKeyValuePairs
     */
    public function __construct(CanListAiPrompts $canListAiPrompts, ListsKeyValuePairs $listsKeyValuePairs)
    {
        $this->canListAiPrompts = $canListAiPrompts;
        $this->listsKeyValuePairs = $listsKeyValuePairs;
    }


    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function logic(Request $request): JsonResponse
    {
        $this->canListAiPrompts->passes();

        $prompts = $this->listsKeyValuePairs->execute(array_merge($this->listsKeyValuePairs->deserializeFilters($request->input('filters')), ['prompt' => false]));

        return $this->collectionResponse(ChatGPTPromptResource::collection($prompts));
    }
}
