<?php

use App\Http\Controllers\AlunosController;
use App\Http\Controllers\EnvioWhatsap;
use App\Http\Controllers\EscolasController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\TurmasController;
use App\Http\Controllers\UsersController;
use Illuminate\Support\Facades\Route;


// Rotas para Guest, sem necessidade de autenticação
Route::middleware('guest')->group(function () {
    Route::get('/', function () {
        return redirect()->route('login');
    });
});


// Rotas para Auth, Necessário autenticação
Route::middleware('auth')->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
    Route::get('/dashboard', function () {
        return view('dashboard');
    })->name('dashboard');
    Route::get('/escolas', [EscolasController::class, 'index'])->name('escolas');
    Route::post('/escolas', [EscolasController::class, 'createOrUpdate'])->name('escola.novo');
    Route::get('/turmas', [TurmasController::class, 'index'])->name('turmas')->middleware('role:admin|super_admin');
    Route::get('/turmas/{id}', [TurmasController::class, 'detalhes'])->name('turmas.detalhes');
    Route::post('/turmas', [TurmasController::class, 'createOrUpdate'])->name('turma.novo');
    Route::get('/alunos', [AlunosController::class, 'index'])->name('alunos')->middleware('permission:alunos.ver_todos|alunos.ver_meus');
    Route::post('/alunos', [AlunosController::class, 'updateOrCreate'])->name('alunos.add')->middleware('role:super_admin');
    Route::post('/envio-wpp', [EnvioWhatsap::class, 'envio'])->name('envio.wpp');
    Route::get('/usuarios', [UsersController::class, 'index'])->name('usuarios')->middleware('role:super_admin');
    Route::post('/usuarios', [UsersController::class, 'store'])->name('usuarios.add')->middleware('role:super_admin');
    Route::get('/api/escolas/{escola}/turmas', [TurmasController::class, 'byEscola'])->name('api.escolas.turmas');
    Route::get('/api/escolas/{escola}/roles', [UsersController::class, 'rolesByEscola'])->name('api.escolas.roles');

    Route::get('/api/escolas/{escola}/alunos', [UsersController::class, 'alunosByEscola'])->name('api.escolas.alunos');
});



require __DIR__ . '/auth.php';
