<?php

declare(strict_types=1);

use Illuminate\Support\Facades\Route;
use ImovelZapAi\Conversations\Infrastructure\Http\Controllers\Api\AiUsageController;
use ImovelZapAi\Conversations\Infrastructure\Http\Controllers\Api\EvolutionWebhookController;
use ImovelZapAi\Conversations\Infrastructure\Http\Controllers\Api\HandoffController;
use ImovelZapAi\Conversations\Infrastructure\Http\Controllers\Api\PropertyInterestController;
use ImovelZapAi\Conversations\Infrastructure\Http\Controllers\Api\WhatsAppWebhookController;

Route::prefix('webhooks')
    ->middleware('api')
    ->group(function (): void {
        Route::get('whatsapp', [WhatsAppWebhookController::class, 'verify']);
        Route::post('whatsapp', [WhatsAppWebhookController::class, 'handle']);
        Route::post('evolution', [EvolutionWebhookController::class, 'handle']);
    });

Route::middleware(['auth:sanctum', 'tenant.resolve', 'tenant.required', 'tenant.active'])
    ->group(function (): void {
        Route::get('ai/usage', [AiUsageController::class, 'index']);

        Route::get('interest', [PropertyInterestController::class, 'index']);
        Route::post('interest', [PropertyInterestController::class, 'store']);
        Route::get('handoff', [HandoffController::class, 'index']);
        Route::post('handoff', [HandoffController::class, 'store']);
        Route::post('handoff/{handoff}/claim', [HandoffController::class, 'claim']);
    });
