import {
    CapabilityName,
    getBase64Middleware,
    getMimeTypesCheckerByRegex,
    validateBodyParams,
    validatePageLimitPagination,
    validateStringQueryParams,
} from '@humand-packages/common';
import { Router } from 'express';
import Container from 'typedi';
import { validateBotAppPermissions } from '../../../auth/presentation/middlewares/jwtAuthenticator';
import { TimeTrackingKioskUserController } from '../controllers/timeTracking/timeTrackingKioskUser';
import { TimeTrackingKioskController } from '../controllers/timeTrackingKiosk';
import { TimeTrackingKioskLinkController } from '../controllers/timeTrackingKioskLink';
import ListKioskCollabsVC from '../validationClasses/listKioskCollabsVC';
import { ListKioskUsersVC } from '../validationClasses/timeTracking/listKioskUsers';
import { ListKioskUsersProfilePictureVC } from '../validationClasses/timeTracking/listKioskUsersProfilePicture';
import { TimeTrackingKioskPinVerifyVC } from '../validationClasses/timeTracking/timeTrackingKioskPinVerifyVC';
import { TimeTrackingKioskLinkGenerateCodeVC } from '../validationClasses/timeTrackingKioskLinkGenerateCodeVC';
import { TimeTrackingKioskLinkValidateCodeVC } from '../validationClasses/timeTrackingKioskLinkValidateCodeVC';

export function startTimeTrackingKioskBotAppsRouter(paginationMaxLimit: number): Router {
    const controller = Container.get(TimeTrackingKioskController);
    const timeTrackingKioskUserController = Container.get(TimeTrackingKioskUserController);
    const router = Router();
    router.get(
        '/collabs',
        validateStringQueryParams(ListKioskCollabsVC),
        validatePageLimitPagination({ maxLimit: paginationMaxLimit, required: true }),
        validateBotAppPermissions([CapabilityName.VIEW_TIME_TRACKING]),
        controller.listCollabs,
    );
    router.get(
        '/users',
        validateStringQueryParams(ListKioskUsersVC),
        validatePageLimitPagination({ maxLimit: paginationMaxLimit, required: true }),
        validateBotAppPermissions([CapabilityName.VIEW_TIME_TRACKING]),
        timeTrackingKioskUserController.listUsers,
    );
    router.get(
        '/users-profile-picture',
        validateStringQueryParams(ListKioskUsersProfilePictureVC),
        validatePageLimitPagination({ maxLimit: paginationMaxLimit, required: true }),
        validateBotAppPermissions([CapabilityName.VIEW_TIME_TRACKING]),
        timeTrackingKioskUserController.listUsersProfilePicture,
    );
    router.post(
        '/pin/verify',
        validateBodyParams(TimeTrackingKioskPinVerifyVC),
        validateBotAppPermissions([CapabilityName.VIEW_TIME_TRACKING]),
        controller.verifyPin,
    );
    router.get('/settings', validateBotAppPermissions([CapabilityName.VIEW_TIME_TRACKING]), controller.settings);
    router.post(
        '/face-clock-base64',
        validateBotAppPermissions([CapabilityName.VIEW_TIME_TRACKING]),
        getBase64Middleware('file'),
        getMimeTypesCheckerByRegex(/image\/(png|jpeg)/),
        controller.faceClock,
    );
    return router;
}

export function startTimeTrackingKioskPublicBotAppsRouter(): Router {
    const controller = Container.get(TimeTrackingKioskLinkController);
    const router = Router();
    router.post('/generate-code', validateBodyParams(TimeTrackingKioskLinkGenerateCodeVC), controller.generateCode);
    router.post('/validate-code', validateBodyParams(TimeTrackingKioskLinkValidateCodeVC), controller.validateCode);
    return router;
}
