import { validateBodyParams, validatePageLimitPagination, validateStringQueryParams } from '@humand-packages/common';
import { Router } from 'express';
import Container from 'typedi';
import { TimeTrackingController } from '../controllers/timeTracking';
import { TimeTrackingFaceAssignmentController } from '../controllers/timeTracking/timeTrackingFaceAssignment';
import { TimeTrackingKioskUserController } from '../controllers/timeTracking/timeTrackingKioskUser';
import { TimeTrackingHourCategorizationController } from '../controllers/timeTrackingHourCategorization';
import { WorkScheduleController } from '../controllers/workSchedule';
import { CloseEntriesRequestVC } from '../validationClasses/closeEntriesRequestVC';
import { FaceAssignmentsBulkIndexFacesVC } from '../validationClasses/timeTracking/faceAssignmentsBulkIndexFacesVC';
import { FaceAssignmentsReconcileVC } from '../validationClasses/timeTracking/faceAssignmentsReconcileVC';
import { KioskUsersSnapshotVC } from '../validationClasses/timeTracking/kioskUsersSnapshotVC';
import { RecalculateCategorizedHoursVC } from '../validationClasses/timeTracking/recalculateCategorizedHoursVC';

export function startTimeTrackingDevopsRouter(): Router {
    const entriesController = Container.get(TimeTrackingController);
    const timeTrackingFaceAssignmentController = Container.get(TimeTrackingFaceAssignmentController);
    const timeTrackingKioskUserController = Container.get(TimeTrackingKioskUserController);
    const hourCategorizationController = Container.get(TimeTrackingHourCategorizationController);
    const router = Router();
    router.post('/entries/autoclose', validateStringQueryParams(CloseEntriesRequestVC), entriesController.closeEntriesForDate);
    router.post(
        '/face-assignments/bulk-index',
        validateBodyParams(FaceAssignmentsBulkIndexFacesVC),
        timeTrackingFaceAssignmentController.bulkIndexFaces,
    );
    router.post('/face-assignments/reconcile', validateBodyParams(FaceAssignmentsReconcileVC), timeTrackingFaceAssignmentController.reconcile);
    router.post('/kiosk-users/snapshot', validateBodyParams(KioskUsersSnapshotVC), timeTrackingKioskUserController.createSnapshot);
    router.post(
        '/categorized-hours/recalculate',
        validateBodyParams(RecalculateCategorizedHoursVC),
        hourCategorizationController.recalculateForDevops,
    );
    return router;
}

export function startWorkScheduleDevopsRouter(): Router {
    const workScheduleController = Container.get(WorkScheduleController);
    const router = Router();
    router.post(
        '/migrate-workdays',
        validatePageLimitPagination({ maxLimit: 10000, required: true }),
        workScheduleController.migrateWorkdaysToWorkSchedules,
    );
    return router;
}
