<?php

declare(strict_types=1);

namespace App\Http\Controllers\Settings;

use App\Http\Controllers\Controller;
use App\Models\Collection;
use App\Services\CollectionAiCurationService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CollectionAiController extends Controller
{
    public function __construct(
        private readonly CollectionAiCurationService $ai,
    ) {
    }

    public function suggestTitle(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->suggestTitle($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function suggestSummary(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->suggestSummary($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function suggestCover(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->suggestCover($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function suggestGrouping(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->suggestGrouping($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function suggestRelatedArtworks(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->suggestRelatedArtworks($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function suggestTags(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->suggestTags($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function suggestSeoDescription(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->suggestSeoDescription($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function explainSmartRules(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->explainSmartRules($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function suggestSplitThemes(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->suggestSplitThemes($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function suggestMergeIdea(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->suggestMergeIdea($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function detectWeakMetadata(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->detectWeakMetadata($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function suggestStaleRefresh(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->suggestStaleRefresh($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function suggestCampaignFit(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->suggestCampaignFit($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }

    public function suggestRelatedCollectionsToLink(Request $request, Collection $collection): JsonResponse
    {
        $this->authorize('update', $collection);

        return response()->json([
            'suggestion' => $this->ai->suggestRelatedCollectionsToLink($collection->loadMissing('user'), (array) $request->input('draft', [])),
        ]);
    }
}
