<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ArticuloController;
use App\Http\Controllers\ChiriuchutxtController;
use App\Http\Controllers\HeaderController;
use App\Http\Controllers\TeamController;
use App\Http\Controllers\MensajeController;
use App\Http\Controllers\ServicioController;
use App\Http\Controllers\ViewController;
use App\Http\Controllers\ComentarioController;
use App\Http\Controllers\BlogController;
use App\Http\Controllers\ServicioChtxtController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/

Route::get('/', [ChiriuchutxtController::class, 'index']);

Route::get('Chiriuchutxt/servicios', [ChiriuchutxtController::class, 'servicios'])->name('Chiriuchutxt.servicios');
Route::resource('Chiriuchutxt', ChiriuchutxtController::class);

// --- FORMULARIO DE COMENTARIOS ---
Route::post('comentarios/guardar', [ComentarioController::class, 'store'])->name('comentarios.store');

// --- SECCIÓN PÚBLICA: BLOG Y SERVICIOS CHIRIUCHUTXT ---
Route::get('/chiriuchutxt.com/blog', [BlogController::class, 'index'])->name('blog.index');
Route::get('/chiriuchutxt.com/blog/{slug}', [BlogController::class, 'show'])->name('blog.show');

Route::get('/chiriuchutxt.com/servicios', [ServicioChtxtController::class, 'index'])->name('servicios.index');
Route::get('/chiriuchutxt.com/servicios/{slug}', [ServicioChtxtController::class, 'show'])->name('servicios.show');

// --- RUTA PÚBLICA PROTEGIDA CONTRA SPAM (Máximo 5 peticiones por minuto por IP) ---
Route::post('/update-view-data/{viewName}', [ViewController::class, 'updateViewData'])
    ->middleware('throttle:5,1');

// --- RUTAS PROTEGIDAS POR AUTENTICACIÓN (Dashboard y Administración) ---
Route::middleware([
    'auth:sanctum',
    config('jetstream.auth_session'),
    'verified', 
])->group(function () {
    Route::get('/dashboard', [ViewController::class, 'getDashboardData'])->name('dashboard');
    
    // Recursos administrativos protegidos
    Route::resource('Articulos', ArticuloController::class);
    Route::resource('Headers', HeaderController::class);
    Route::resource('Teams', TeamController::class);
    Route::resource('Servicios', ServicioController::class);

    // --- RUTAS PERSONALIZADAS DE MENSAJES ---
    Route::delete('mensajes/destroy-multiple', [MensajeController::class, 'destroyMultiple'])->name('mensajes.destroyMultiple');
    Route::get('mensajes/refresh', [MensajeController::class, 'refresh'])->name('mensajes.refresh');
    Route::resource('Mensajes', MensajeController::class);
});