<?php

use App\Http\Controllers\Auth\AuthController;
use App\Http\Controllers\SetController;
use Illuminate\Support\Facades\Route;

// ── Raíz ──────────────────────────────────────────────
Route::get('/', fn () => redirect()->route('login'));

// ── Autenticación ──────────────────────────────────────
Route::middleware('guest')->group(function () {
    Route::get('/login', [AuthController::class, 'showLogin'])->name('login');
    Route::post('/login', [AuthController::class, 'login']);
});

Route::post('/logout', [AuthController::class, 'logout'])
    ->middleware('auth')
    ->name('logout');

// ── Rutas protegidas ───────────────────────────────────
Route::middleware('auth')->group(function () {
    Route::get('/dashboard', fn () => redirect()->route('sets.index'))->name('dashboard');

    Route::resource('sets', SetController::class)
        ->only(['index', 'create', 'store', 'show']);

    // API interna
    Route::get('/api/sets', [SetController::class, 'obtenerSets']);
    Route::get('/api/sets/{codSet}/referencias', [SetController::class, 'obtenerReferenciasSet'])
    ->where('codSet', '.*');
});
