import {
    TimeTrackingKioskResponse,
    TimeTrackingKioskStatus as GrpcTimeTrackingKioskStatus,
} from '../../../../../grpc/generated/exposed/humand/timetracking/v1/timetracking_kiosk_service';
import { TimeTrackingKiosk } from '../../models/timeTrackingKiosk';
import { TimeTrackingKioskStatus } from '../../types/kioskStatus';

const mapStatus = (status: string | undefined): GrpcTimeTrackingKioskStatus => {
    const statusMap: Record<TimeTrackingKioskStatus, GrpcTimeTrackingKioskStatus> = {
        [TimeTrackingKioskStatus.UNLINKED]: GrpcTimeTrackingKioskStatus.TIME_TRACKING_KIOSK_STATUS_UNLINKED,
        [TimeTrackingKioskStatus.WAITING_FOR_LINK]: GrpcTimeTrackingKioskStatus.TIME_TRACKING_KIOSK_STATUS_WAITING_FOR_LINK,
        [TimeTrackingKioskStatus.ACTIVE]: GrpcTimeTrackingKioskStatus.TIME_TRACKING_KIOSK_STATUS_ACTIVE,
    };
    return statusMap[status as TimeTrackingKioskStatus] ?? GrpcTimeTrackingKioskStatus.TIME_TRACKING_KIOSK_STATUS_UNSPECIFIED;
};

export const mapTimeTrackingKioskToGrpcResponse = (kiosk: TimeTrackingKiosk): TimeTrackingKioskResponse => {
    return {
        botAppId: kiosk.botAppId!,
        createdBy: kiosk.createdBy!,
        description: kiosk.description,
        faceRecognitionBlocking: kiosk.faceRecognitionBlocking,
        faceRecognitionEnabled: kiosk.faceRecognitionEnabled,
        id: kiosk.id,
        name: kiosk.name,
        pinAuthenticationEnabled: kiosk.pinAuthenticationEnabled ?? false,
        siteId: kiosk.siteId ?? undefined,
        status: mapStatus(kiosk.status),
    };
};
