import { Router, type IRouter } from 'express';
import { authenticate, authorize } from '../middlewares/auth.middleware.js';
import { tenantMiddleware } from '../middlewares/tenant.middleware.js';
import * as ctrl from '../controllers/tareas.controller.js';
import * as asignacionesCtrl from '../controllers/asignaciones.controller.js';

const router: IRouter = Router();

router.use(authenticate);
router.use(tenantMiddleware);

router.get('/mis-tareas', ctrl.listMisTareas);
router.get('/', ctrl.listTareas);
router.post('/', ctrl.createTarea);
router.post('/seed', ctrl.seedDefaults);
router.patch('/:id', ctrl.updateTarea);
router.delete('/:id', ctrl.deleteTarea);

router.post('/periodo/:id/completar', ctrl.completarPeriodo);
router.delete('/periodo/:id/completar', ctrl.descompletarPeriodo);

// Asignación de tareas a auxiliares (supervisor/owner)
router.post('/:id/asignar', authorize('owner', 'supervisor'), asignacionesCtrl.asignarTarea);
router.delete('/:id/asignar', authorize('owner', 'supervisor'), asignacionesCtrl.desasignarTarea);

export { router as tareasRoutes };
