<?php

use App\Http\Controllers\AlumnosBitacoraController;
use App\Http\Controllers\Api\ActividadController;
use App\Http\Controllers\Api\AsistenciaController;
use App\Http\Controllers\Api\CategoriasMateriasController;
use App\Http\Controllers\Api\CircularesController;
use App\Http\Controllers\Api\EventosController;
use App\Http\Controllers\Api\GradoEducativoController;
use App\Http\Controllers\Api\GrupoController;
use App\Http\Controllers\Api\MateriaController;
use App\Http\Controllers\Api\PeriodoController;
use App\Http\Controllers\Api\TareasController;
use App\Http\Controllers\Api\UserController;
use App\Http\Controllers\auth\LoginController;
use App\Http\Controllers\MailController;
use App\Http\Controllers\PersonalizarController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\AlumnosController;
use App\Http\Controllers\Api\ProfesoresController;
use App\Http\Controllers\Api\PeriodosBoletaController;
use App\Http\Controllers\Api\TiposInfoGeneralController;
use App\Http\Controllers\Api\TiposRegistroBitacoraController;
use App\Http\Controllers\Api\TiposTareasController;
use App\Http\Controllers\Api\NivelEducativoController;
use App\Http\Controllers\Api\RegistroAcademico;
use App\Http\Controllers\Api\profesorRegistroBitacora;
use App\Http\Controllers\Api\RegistroCalicaciones;
use App\Http\Controllers\NivelExportController;
use App\Http\Controllers\FormController;
use App\Http\Controllers\RespuestasController;
use App\Http\Controllers\s3;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/

// Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
//     return $request->user();
// });

//RUTAS QUE NO NECESITAN TOKENS
Route::post('/subir-archivo', [s3::class, 'subirArchivo']);
Route::post('/recalcular-completado', [RegistroAcademico::class, 'RecalcularCompletado']);

Route::post('login', [LoginController::class, 'login']);
Route::post('register', [UserController::class, 'register']);
Route::post('/verifyTokens', [LoginController::class, 'checkUserTokens']);
Route::post('actividad', [ActividadController::class, 'store']);
Route::get('ipLocal', [ActividadController::class, 'localIP']);
Route::put('changePassword', [LoginController::class, 'updatePassword']);
Route::get('personalizarInfo', [PersonalizarController::class, 'show']);
Route::post('/send-test-email', [MailController::class, 'sendTestEmail']);
Route::get('/exportar-excel', [NivelExportController::class, 'exportarExcel']);
Route::get('/exportar-alumnos', [NivelExportController::class, 'exportarAlumnosRegistro']);


//protección de rutas
Route::middleware(['auth:sanctum'])->group(function () {
    Route::get('logout', [LoginController::class, 'logout']);

    // Rutas Periodos
    Route::post('crearPeriodo', [PeriodoController::class, 'crearPeriodo']);
    Route::get('getAllPeriodos', [PeriodoController::class, 'getAllPeriodos']);
    Route::post('activarPeriodo', [PeriodoController::class, 'activarPeriodo']);
    Route::post('deshabilitarPeriodo', [PeriodoController::class, 'eliminarPeriodo']);
    Route::post('habilitarPeriodo', [PeriodoController::class, 'habilitarPeriodo']);


    //Rutas de Usuarios
    Route::get('count', [ActividadController::class, 'count']);
    Route::get('usuarioAll', [UserController::class, 'mostrar']);
    Route::get('usuarioHabilitados', [UserController::class, 'materiasHabilitadas']);
    Route::get('usuarioOne/{id}', [UserController::class, 'findOne']);
    Route::put('usuarioE', [UserController::class, 'actualizar']);
    Route::put('usuarioDelete/{id}', [UserController::class, 'eliminar']);
    Route::put('usuarioEnable/{id}', [UserController::class, 'habilitar']);

    //Rutas de Circulares
    Route::get('circularAll', [CircularesController::class, 'mostrar']);
    Route::post('eliminarArchivoS3', [CircularesController::class, 'eliminarArchivo']);

    Route::get('circularUlt', [CircularesController::class, 'ultimasCirc']);
    Route::post('circularSave', [CircularesController::class, 'crear']);
    Route::get('circularOne/{id}', [CircularesController::class, 'findOne']);
    Route::get('extraInfo/{id}', [CircularesController::class, 'extraInfo']);
    Route::put('circularE', [CircularesController::class, 'actualizar']);
    Route::put('circularDelete/{id}', [CircularesController::class, 'eliminar']);
    Route::put('circularEnable/{id}', [CircularesController::class, 'habilitar']);
    Route::get('download/{id}', [CircularesController::class, 'download']);
    Route::post('idUserCircular', [CircularesController::class, 'getUsuariosCircular']); //Obtener usuarios para enviar circulares
    Route::post('crearDestino', [CircularesController::class, 'crearDestinoCircular']); //crear destino de usuarios para enviar circulares
    Route::get('getByUserC/{id}', [CircularesController::class, 'getByUser']); //Obtener circulares por usuario
    Route::get('estadisticas/{id}', [CircularesController::class, 'estadisticas']); //Obtener estadisticas de circulares
    Route::post('actualizarVisto', [CircularesController::class, 'actualizarVisto']); //Actualizar visto de circulares

    //actividad - Sesión
    Route::get('actividades', [ActividadController::class, 'index']);
    Route::get('actividad/{id}', [ActividadController::class, 'show']);

    //personalizar
    Route::put('personalizar', [PersonalizarController::class, 'update']);

    //Rutas de Nivel Educativo
    Route::get('nivelEducativoAll', [NivelEducativoController::class, 'mostrar']);
    Route::get('nivelEducativoHabilitado', [NivelEducativoController::class, 'nivelesHabilitados']);
    Route::get('nivelEducativoOne/{id}', [NivelEducativoController::class, 'findOne']);
    Route::post('nivelEducativoSave', [NivelEducativoController::class, 'crear']);
    Route::put('nivelEducativoE', [NivelEducativoController::class, 'actualizar']);
    Route::put('nivelEducativoDelete/{id}', [NivelEducativoController::class, 'eliminar']);
    Route::put('nivelEducativoEnable/{id}', [NivelEducativoController::class, 'habilitar']);

    //Rutas de Eventos
    Route::post('eventoSave', [EventosController::class, 'crear']);
    Route::post('savecalendarioUsuarios', [EventosController::class, 'savecalendarioUsuarios']);
    Route::get('eventosAll', [EventosController::class, 'eventosActivos']);
    Route::get('eventosSemana', [EventosController::class, 'getWeekEvents']);


    //Rutas de Grados Educativos
    Route::get('gradoEducativoAll', [GradoEducativoController::class, 'mostrar']);
    Route::get('gradoEducativoHabilitado', [GradoEducativoController::class, 'gradosHabilitados']);
    Route::get('gradoEducativoOne/{id}', [GradoEducativoController::class, 'findOne']);
    Route::post('gradoEducativoSave', [GradoEducativoController::class, 'crear']);
    Route::put('gradoEducativoE', [GradoEducativoController::class, 'actualizar']);
    Route::put('gradoEducativoDelete/{id}', [GradoEducativoController::class, 'eliminar']);
    Route::put('gradoEducativoEnable/{id}', [GradoEducativoController::class, 'habilitar']);

    //Rutas de Grupos
    Route::get('grupoAll', [GrupoController::class, 'mostrar']);
    Route::get('grupoHabilitado', [GrupoController::class, 'gruposHabilitados']);
    Route::get('grupoOne/{id}', [GrupoController::class, 'findOne']);
    Route::post('grupoSave', [GrupoController::class, 'crear']);
    Route::put('grupoE', [GrupoController::class, 'actualizar']);
    Route::put('grupoDelete/{id}', [GrupoController::class, 'eliminar']);
    Route::put('grupoEnable/{id}', [GrupoController::class, 'habilitar']);

    //Rutas de Categorias de Materias
    Route::get('categoriaAll', [CategoriasMateriasController::class, 'mostrar']);
    Route::get('categoriaHabilitado', [CategoriasMateriasController::class, 'categoriasHabilitadas']);
    Route::get('categoriaOne/{id}', [CategoriasMateriasController::class, 'findOne']);
    Route::post('categoriaSave', [CategoriasMateriasController::class, 'crear']);
    Route::put('categoriaE', [CategoriasMateriasController::class, 'actualizar']);
    Route::put('categoriaDelete/{id}', [CategoriasMateriasController::class, 'eliminar']);
    Route::put('categoriaEnable/{id}', [CategoriasMateriasController::class, 'habilitar']);

    //Rutas de Materias
    Route::get('materiaAll', [MateriaController::class, 'mostrar']);
    Route::get('materiaHabilitado', [MateriaController::class, 'materiasHabilitadas']);
    Route::get('materiaOne/{id}', [MateriaController::class, 'findOne']);
    Route::post('materiaSave', [MateriaController::class, 'crear']);
    Route::put('materiaE', [MateriaController::class, 'actualizar']);
    Route::put('materiaDelete/{id}', [MateriaController::class, 'eliminar']);
    Route::put('materiaEnable/{id}', [MateriaController::class, 'habilitar']);

    //Anuncios
    Route::get('getProfes/{id}', [MateriaController::class, 'getProfes']);
    Route::post('crearAnuncio', [MateriaController::class, 'crearAnuncio']);
    Route::put('anuncioE', [MateriaController::class, 'editarAnuncio']);
    Route::put('anuncioEliminar/{id}', [MateriaController::class, 'eliminarAnuncio']);

    //Rutas de Asistencia
    Route::get('asistenciaAll', [AsistenciaController::class, 'mostrar']);
    Route::post('asistenciaSave', [AsistenciaController::class, 'crear']);
    Route::put('actualizarRegistro', [AsistenciaController::class, 'actualizar']);
    Route::put('asistenciaDelete/{id}', [AsistenciaController::class, 'eliminar']);

    // ---------------------------------------------------------------------------------------------------------------------------------------------------

    //Rutas de Tipos de tareas
    Route::get('tipoTarea', [TiposTareasController::class, 'mostrarTodos']);
    Route::post('tipoTareas', [TiposTareasController::class, 'crear']);
    Route::put('tipoTareas/{idTareasTipos}', [TiposTareasController::class, 'editar']);
    Route::put('eliminar/{id}', [TiposTareasController::class, 'Actualizar']);
    Route::put('habilitar/{id}', [TiposTareasController::class, 'Habilitar']);

    //Rutas de Tipos de registro de bitacora
    Route::get('registroBitacoraT', [TiposRegistroBitacoraController::class, 'mostrarTodos']);
    Route::post('registroBitacora', [TiposRegistroBitacoraController::class, 'crear']);
    Route::put('registroBitacora/{idBitacorasTipos}', [TiposRegistroBitacoraController::class, 'editar']);
    Route::put('habilitarEstadoRB/{id}', [TiposRegistroBitacoraController::class, 'HabilitarE']);
    Route::put('eliminarEstadoRB/{id}', [TiposRegistroBitacoraController::class, 'EliminarE']);

    //Rutas de Tipos de informacion general
    Route::get('infoGeneralT', [TiposInfoGeneralController::class, 'mostrarTodos']);
    Route::post('infoGeneral', [TiposInfoGeneralController::class, 'crear']);
    Route::put('infoGeneral/{id}', [TiposInfoGeneralController::class, 'editar']);
    Route::put('eliminarEstado/{id}', [TiposInfoGeneralController::class, 'eliminarEstado']);
    Route::put('habilitarEstado/{id}', [TiposInfoGeneralController::class, 'habilitarEstado']);

    //Rutas de periodos boleta
    Route::get('periodoBoletaT', [PeriodosBoletaController::class, 'mostrarTodos']);
    Route::post('periodoBoleta', [PeriodosBoletaController::class, 'crear']);
    Route::put('periodoBoleta/{id}', [PeriodosBoletaController::class, 'editar']);
    Route::put('eliminarEstadoPB/{id}', [PeriodosBoletaController::class, 'eliminarEstado']);
    Route::put('habilitarEstadoPB/{id}', [PeriodosBoletaController::class, 'habilitarEstado']);
    // ---------------------------------------------------------------------------------------------------------------------------------------------------

    //Rutas Para relacionar Alumnos
    Route::get('alumnos', [AlumnosController::class, 'getAlumnos']);
    Route::get('alumnosRegistro', [AlumnosController::class, 'alumnosRegistro']);
    Route::get('getPadres', [AlumnosController::class, 'getPadres']);
    Route::post('AlumnoGrupo', [AlumnosController::class, 'RelacionAlumnosGrupo']);
    Route::post('AlumnoPadre', [AlumnosController::class, 'RelacionAlumnosPadre']);
    Route::delete('eliminarGrupo', [AlumnosController::class, 'eliminarGrupo']);
    Route::delete('eliminarPadre', [AlumnosController::class, 'eliminarPadre']);
    Route::get('/alumnos/bitacora/{id}', [AlumnosBitacoraController::class, 'index']);
    Route::get('getByUser/{id}', [AlumnosBitacoraController::class, 'getByUser']); //Obtener circulares por usuario
    Route::get('UserOne/{id}', [AlumnosBitacoraController::class, 'findOne']);



    // Rutas para Relacionar Profesores
    Route::get('profesores', [ProfesoresController::class, 'mostrarProfesores']);
    Route::post('RelacionarProfesor', [ProfesoresController::class, 'RelacionarProfesor']);
    Route::get('getMaterias', [ProfesoresController::class, 'getMaterias']);
    Route::delete('eliminarRelacion', [ProfesoresController::class, 'eliminarRelacion']);
    Route::get('getGrupos/{id}', [ProfesoresController::class, 'getGrupos']);

    //Ruta para Registro Academico
    Route::get('getOneRegistro/{id}', [RegistroAcademico::class, 'getOneRegistro']);
    Route::get('UserOne/{id}', [RegistroAcademico::class, 'findOne']);
    Route::get('getAll', [RegistroAcademico::class, 'getAll']);
    Route::post('registroAca', [RegistroAcademico::class, 'registroAca']);
    Route::put('updateRegistro/{id}', [RegistroAcademico::class, 'ActualizarRegistroAca']);

    //Ruta para Registro Administrativo
    Route::get('getAllAd', [RegistroAcademico::class, 'getAllAd']);
    Route::post('registroAdministrativo', [RegistroAcademico::class, 'registroAdministrativo']);
    Route::get('getRegistroAdmin/{id}', [RegistroAcademico::class, 'getOneRegistroAdmi']);
    Route::post('editarRegistroAdmin/{id}', [RegistroAcademico::class, 'editarRegistroAdmin']);
    Route::get('getAllPlanPago', [RegistroAcademico::class, 'getAllPlanPago']);
    Route::get('getAllPorcentajeBeca', [RegistroAcademico::class, 'getAllPorcentajeBeca']);
    Route::get('getAllMetodoPago', [RegistroAcademico::class, 'getAllMetoPago']);
    Route::get('/constancia-fiscal/descargar/{idAlumno}', [RegistroAcademico::class, 'descargarConstanciaFiscal']);


    //Ruta para Profesor Registro Bitacora
    Route::get('getRegistrosP', [profesorRegistroBitacora::class, 'getRegistrosP']);
    Route::get('getMateriasP', [profesorRegistroBitacora::class, 'getMateriasP']);
    Route::get('getTiposP', [profesorRegistroBitacora::class, 'Tipos']);
    Route::get('getAlumnosP', [profesorRegistroBitacora::class, 'getAlumnos']);
    Route::post('crearBitacoraP', [profesorRegistroBitacora::class, 'crearBitacora']);
    Route::put('editarBitacoraP/{id}', [profesorRegistroBitacora::class, 'editarBitacora']);
    Route::put('eliminarBitacoraP/{id}', [profesorRegistroBitacora::class, 'eliminarBitacora']);
    Route::put('habilitarBitacoraP/{id}', [profesorRegistroBitacora::class, 'habilitarBitacora']);

    //Ruta para registroCalificaciones
    Route::get('getCalificaciones', [RegistroCalicaciones::class, 'getCalificaciones']);
    Route::get('getPeriodosCalificacion', [RegistroCalicaciones::class, 'getPeriodos']);
    Route::post('registrarCalificacion', [RegistroCalicaciones::class, 'registrarCalificacion']);
    Route::post('registrarCalificacionesMasivas', [RegistroCalicaciones::class, 'registrarCalificacionesMasivas']);
    Route::put('editarCalificacion', [RegistroCalicaciones::class, 'editarCalificacion']);
    Route::put('elminarEstadoCalificacion', [RegistroCalicaciones::class, 'eliminarEstado']);
    Route::put('habilitarEstadoCalificacion', [RegistroCalicaciones::class, 'habilitarEstado']);

    Route::get('getAlumnosCalificacion', [RegistroCalicaciones::class, 'getCalificacionesMateria']);
    Route::get('/personalizacion/nombre-colegio', [PersonalizarController::class, 'getNombreColegio']);
    Route::get('/personalizacion/eslogan-colegio', [PersonalizarController::class, 'getEsloganColegio']);


    //ADMINISTRADOR DE FORMULARIOS RUTAS
    Route::post('/createForm', [FormController::class, 'store']); // Crear un nuevo formulario
    Route::get('/formularios', [FormController::class, 'getAll']);
    Route::get('/formulario/{id}', [FormController::class, 'getFormById']);
    Route::put('/updateForm/{id}', [FormController::class, 'update']);
    Route::delete('/forms/{id}', [FormController::class, 'destroy']);
    Route::put('formularios/{id}/publish', [FormController::class, 'publish']);
    Route::put('formularios/{id}/unpublish', [FormController::class, 'unpublish']);
    Route::get('/formularios/publicado', [FormController::class, 'getPublicado']);


    //Respuestas de Formularios creados
    Route::post('/recibirRespuesta', [RespuestasController::class, 'recibirRespuesta']);
    Route::get('/generar-pdf/{id_usuario}/{form_id}', [RespuestasController::class, 'generarPDF']);
    Route::get('/respuestas/check', [RespuestasController::class, 'tieneRespuesta']);
    Route::get('/respuestas/formulario', [RespuestasController::class, 'obtenerRespuesta']);
    Route::put('/actualizarRespuesta', [RespuestasController::class, 'actualizarRespuesta']);

    Route::post('/eliminarArchivo', [RegistroAcademico::class, 'eliminarArchivo']);
    Route::post('/eliminarPerlogo', [PersonalizarController::class, 'eliminarPerlogo']);

    Route::get('/personalizar/perlogo1', [PersonalizarController::class, 'getPerLogo1Base64']);
    Route::get('/personalizar/perlogo2', [PersonalizarController::class, 'getPerLogo2Base64']);



    // Rutas para tareas
    Route::get('/getAllTareas', [TareasController::class, 'getAllTareas']);
    Route::post('/crearTarea', [TareasController::class, 'crear']);
    Route::put('/tareas/{idTarea}', [TareasController::class, 'actualizar']);
    Route::get('/materias/{id}/alumnos', [TareasController::class, 'obtenerAlumnosPorMateria']);
    Route::post('/tareas-usuarios', [TareasController::class, 'asignarTareaUsuario']);
    Route::get('/tareas/usuario/{idUsuario}', [TareasController::class, 'getTareasPorUsuario']);
    Route::put('tareaDelete/{id}', [TareasController::class, 'eliminar']);
    Route::put('tareaEnable/{id}', [TareasController::class, 'habilitar']);
    Route::get('tareas/fecha-entrega/{fecha}/{idUsuario}', [TareasController::class, 'getTareasPorFechaEntrega']);
    Route::get('tareas/fecha-asignacion/{fecha}/{idUsuario}', [TareasController::class, 'getTareasPorFechaAsignacion']);
    Route::get('tareas/materia/{idMateria}', [TareasController::class, 'getTareasPorMateria']);
    Route::get('tareas/materiaUlt30/{idUsuario}', [TareasController::class, 'getMateriasUsuarioUltimos30Dias']);



});
