<?php

namespace App\Classes\Modules\KeyValuePairs\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\KeyValuePairs\Services\DeletesKeyValuePair;
use App\Classes\Modules\KeyValuePairs\Services\FetchesKeyValuePair;
use App\Classes\Modules\KeyValuePairs\Standards\Rules\CanDeleteChatGPTPrompt;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class DeleteChatGPTPromptKVPLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification(): array
    {
        return [
            'title' => 'Delete ChatGPT Prompt',
            'message' => 'You have successfully deleted the ChatGPT Prompt'
        ];
    }

    /** @var CanDeleteChatGPTPrompt */
    private $canDeleteChatGPTPrompt;

    /** @var FetchesKeyValuePair */
    private $fetchesKeyValuePair;

    /** @var DeletesKeyValuePair */
    private $deletesKeyValuePair;

    /**
     * DeleteChatGPTPromptKVPLogic constructor.
     * @param CanDeleteChatGPTPrompt $canDeleteChatGPTPrompt
     * @param FetchesKeyValuePair $fetchesKeyValuePair
     * @param DeletesKeyValuePair $deletesKeyValuePair
     */
    public function __construct(
        CanDeleteChatGPTPrompt $canDeleteChatGPTPrompt,
        FetchesKeyValuePair $fetchesKeyValuePair,
        DeletesKeyValuePair $deletesKeyValuePair
    ) {
        $this->canDeleteChatGPTPrompt = $canDeleteChatGPTPrompt;
        $this->fetchesKeyValuePair = $fetchesKeyValuePair;
        $this->deletesKeyValuePair = $deletesKeyValuePair;
    }

    /**
     * @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->canDeleteChatGPTPrompt->passes();

        $kvp = $this->fetchesKeyValuePair->execute(['id' => $request->route('id')]);

        $this->deletesKeyValuePair->execute($kvp);

        return $this->response([]);
    }
}
