<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ChatController;
use App\Http\Controllers\AiAssistantController;

Route::prefix('dashboard/messages')->name('chat.')->group(function () {
    
    // Load the main Chat UI
    Route::get('/', [ChatController::class, 'index'])->name('index');
    
    // --- Endpoint for Polling Unread Count ---
    Route::get('/unread-count', [ChatController::class, 'getUnreadCount'])->name('unread');
    
    // Start a new chat from a product/store page
    Route::post('/start', [ChatController::class, 'startChat'])->name('start');
    
    // Fetch messages for a specific conversation via API
    Route::get('/{conversation}', [ChatController::class, 'getMessages'])->name('messages');
    
    // Send a new message to a specific conversation
    Route::post('/{conversation}', [ChatController::class, 'store'])->name('store');

    // --- AI ENDPOINT HERE ---
    Route::post('/{conversation}/ai-reply', [AiAssistantController::class, 'generateChatReply'])->name('ai.reply');
    
});