<?php

use Modules\VetAI\Http\Controllers\InstallController;
use Modules\VetAI\Http\Controllers\VaiSettingsController;
use Modules\VetAI\Http\Controllers\VaiAssistantController;
use Modules\VetAI\Http\Controllers\VaiQueryController;
use Modules\VetAI\Http\Controllers\VaiAppointmentController;
use Modules\VetAI\Http\Controllers\VaiTranscriptionController;

// Install / Update routes
Route::middleware(['web', 'auth'])->prefix('vet-ai')->group(function () {
    Route::get('/install',   [InstallController::class, 'index']);
    Route::post('/install',  [InstallController::class, 'install']);
    Route::get('/uninstall', [InstallController::class, 'uninstall']);
    Route::get('/update',    [InstallController::class, 'update']);
    Route::get('/repair',    [InstallController::class, 'repair']);
});

// Admin routes
Route::group([
    'middleware' => ['web', 'auth', 'SetSessionData', 'language', 'timezone', 'AdminSidebarMenu', 'module:VetAI'],
    'prefix'     => 'vet-ai',
], function () {

    // AI Assistant
    Route::get('/assistant',                [VaiAssistantController::class, 'index'])->name('vai.assistant.index');
    Route::get('/assistant/pet/{id}',       [VaiAssistantController::class, 'petContext'])->name('vai.assistant.pet-context');
    Route::post('/assistant/ask',           [VaiAssistantController::class, 'ask'])->name('vai.assistant.ask');

    // Appointment-integrated AI checkpoints
    Route::post('/appointments/{id}/ai-generate', [VaiAppointmentController::class, 'generate'])->name('vai.appointment.generate');

    // Voice-to-text (SOAP dictation) + clinical NLP — MOVED to VetClinic
    // (Modules\VetClinic\Http\Controllers\VcAiController) so all vet AI runs on
    // the shared AiCore engine. The route names (vai.transcribe, vai.soap-structure,
    // vai.match-chips, vai.suggest-specialist-exams, vai.extract-symptoms,
    // vai.cache-advice) are now registered in VetClinic/Routes/web.php; the
    // consultation view's route('vai.*') references resolve there unchanged.

    // AI query history
    Route::get('/history',                  [VaiQueryController::class, 'index'])->name('vai.queries.index');
    Route::get('/history/list',             [VaiQueryController::class, 'list'])->name('vai.queries.list');
    Route::get('/history/{id}',             [VaiQueryController::class, 'show'])->name('vai.queries.show');

    // Settings
    Route::get('/settings',                 [VaiSettingsController::class, 'index'])->name('vai.settings.index');
    Route::post('/settings/save',           [VaiSettingsController::class, 'save'])->name('vai.settings.save');
    Route::post('/settings/test',           [VaiSettingsController::class, 'test'])->name('vai.settings.test');
});
