const router = require('express').Router();
const ctrl = require('../controllers/timesheet.controller');
const { authenticate, authorize } = require('../middlewares/auth');
const { validate } = require('../middlewares/validate');
const { timesheetSchemas, paramsSchemas } = require('../validators');

router.use(authenticate);

router.post('/clock-in', validate({ body: timesheetSchemas.pin }), ctrl.clockIn);
router.post('/clock-out', validate({ body: timesheetSchemas.pin }), ctrl.clockOut);
router.post('/manual-clock-in', authorize('admin'), validate({ body: timesheetSchemas.empty }), ctrl.manualClockIn);
router.post('/manual-clock-out', authorize('admin'), validate({ body: timesheetSchemas.empty }), ctrl.manualClockOut);
router.get('/me', ctrl.getMyAttendance);
router.get('/report', authorize('admin', 'manager'), ctrl.getAttendanceReport);
router.get('/punches', authorize('admin', 'manager'), ctrl.getPunchHistory);
router.get('/:id/history', authorize('admin', 'manager'), validate({ params: paramsSchemas.idParam }), ctrl.getEntryHistory);
router.put('/:id', authorize('admin', 'manager'), validate({ params: paramsSchemas.idParam, body: timesheetSchemas.updateEntry }), ctrl.updateEntry);
router.delete('/:id', authorize('admin', 'manager'), validate({ params: paramsSchemas.idParam }), ctrl.deleteEntry);

module.exports = router;
