import { validatePageLimitPagination, validateStringQueryParams } from '@humand-packages/common';
import { Router } from 'express';
import Container from 'typedi';
import { validateAndSanitizeBodyParams } from '../../../../middlewares/validateAndSanitizeBodyParams';
import { PublicTimeTrackingController } from '../controllers/publicTimeTracking';
import { ShiftManagementController } from '../controllers/shiftManagement';
import { CreateTimeTrackingEntryAPIRequestsVC } from '../validationClasses/createTimeTrackingEntryAPIRequestVC';
import { GetTimeTrackingDaySummaryAPIRequestsVC } from '../validationClasses/getTimeTrackingDaySummaryAPIRequestVC';
import { GetTimeTrackingEntryAPIRequestsVC } from '../validationClasses/getTimeTrackingEntryAPIRequestVC';
import { GetPublicCalendarAPIRequestVC } from '../validationClasses/shiftManagement/getPublicCalendarAPIRequestVC';
import { ShiftAssignBulkRequestVC } from '../validationClasses/shiftManagement/shiftAssignBulkRequestVC';

export function startTimeTrackingPublicApiRouter(paginationMaxLimit: number): Router {
    const controller = Container.get(PublicTimeTrackingController);

    const router = Router();
    router.post('/entries/clockIn', validateAndSanitizeBodyParams(CreateTimeTrackingEntryAPIRequestsVC), controller.clockIn);
    router.post('/entries/clockOut', validateAndSanitizeBodyParams(CreateTimeTrackingEntryAPIRequestsVC), controller.clockOut);
    router.get(
        '/entries',
        validatePageLimitPagination({ maxLimit: paginationMaxLimit, required: true }),
        validateStringQueryParams(GetTimeTrackingEntryAPIRequestsVC),
        controller.listEntries,
    );
    router.delete('/entries', validateStringQueryParams(GetTimeTrackingEntryAPIRequestsVC), controller.deleteEntries);

    router.get(
        '/day-summaries',
        validatePageLimitPagination({ maxLimit: paginationMaxLimit, required: true }),
        validateStringQueryParams(GetTimeTrackingDaySummaryAPIRequestsVC),
        controller.listDaySummaries,
    );

    return router;
}

export function startShiftManagementPublicApiRouter(paginationMaxLimit: number): Router {
    const controller = Container.get(ShiftManagementController);
    const router = Router();
    router.post('/bulk-create', validateAndSanitizeBodyParams(ShiftAssignBulkRequestVC), controller.bulkProcessShifts);
    router.get(
        '/calendar',
        validatePageLimitPagination({ maxLimit: paginationMaxLimit, required: true }),
        validateStringQueryParams(GetPublicCalendarAPIRequestVC),
        controller.getPublicCalendar,
    );
    router.get('/templates', validatePageLimitPagination({ maxLimit: paginationMaxLimit, required: true }), controller.listShiftTemplates);
    return router;
}
