<?php

namespace App\Http\Controllers\Api\AI;

use App\Domains\AI\Actions\GenerateOrderDraftAction;
use App\Domains\Conversations\Models\Conversation;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;

class OrderDraftController extends Controller
{
    public function __invoke(string $conversation, GenerateOrderDraftAction $generateOrderDraft): JsonResponse
    {
        $record = Conversation::query()
            ->where('tenant_id', request()->user()->tenant_id)
            ->findOrFail($conversation);

        return response()->json(
            $generateOrderDraft->execute(request()->user(), $record)
        );
    }
}
