import { Expose, Type } from 'class-transformer';
import { IsArray, IsBoolean, IsInt, IsIn, IsOptional, IsString, Max, MaxLength, Min, ValidateNested } from 'class-validator';
import {
    MAX_AUTO_CLOSE_FIXED_HOURS_VALUE,
    MAX_AUTO_CLOSE_FIXED_MINUTES_VALUE,
    MAX_AUTO_CLOSE_LIMIT_HOURS,
    MIN_AUTO_CLOSE_FIXED_HOURS_VALUE,
    MIN_AUTO_CLOSE_FIXED_MINUTES_VALUE,
    MIN_AUTO_CLOSE_LIMIT_HOURS,
} from '../../business/constants/timeTrackingPolicy';
import { TimeTrackingPolicyAutoCloseMode } from '../../business/enum/timeTracking/policy';
import { AutoCloseLimitHoursValidator } from './decorators/autoCloseLimitHoursValidator';
import { TimeTrackingPolicyHourCategoryForCreationVC } from './TimeTrackingPolicyHourCategoryForCreationVC';

const MAX_LATENESS_TOLERANCE = 240;
const MIN_LATENESS_TOLERANCE = 0;

export class TimeTrackingPoliciesUpdateVC {
    @IsOptional()
    @IsString()
    @MaxLength(255)
    @Expose()
    name?: string;

    @IsOptional()
    @IsString()
    @Expose()
    description?: string;

    @IsOptional()
    @IsBoolean()
    @Expose()
    clockingInAppEnabled?: boolean;

    @IsOptional()
    @IsBoolean()
    @Expose()
    clockingInWebEnabled?: boolean;

    @IsOptional()
    @IsBoolean()
    @Expose()
    faceRecognitionEnabled?: boolean;

    @IsOptional()
    @IsBoolean()
    @Expose()
    faceRecognitionBlocking?: boolean;

    @IsOptional()
    @IsBoolean()
    @Expose()
    notificationsEnabled?: boolean;

    @IsOptional()
    @IsBoolean()
    @Expose()
    nightShift?: boolean;

    @IsOptional()
    @IsBoolean()
    @Expose()
    clockingInKioskEnabled?: boolean;

    @IsInt()
    @Min(MIN_LATENESS_TOLERANCE)
    @Max(MAX_LATENESS_TOLERANCE)
    @Expose()
    latenessTolerance?: number;

    @IsOptional()
    @IsInt()
    @Expose()
    @Min(MIN_AUTO_CLOSE_LIMIT_HOURS)
    @Max(MAX_AUTO_CLOSE_LIMIT_HOURS)
    @AutoCloseLimitHoursValidator({
        message: 'autoCloseLimitHours must be greater than or equal to (autoCloseFixedHoursValue + autoCloseFixedMinutesValue / 60)',
    })
    autoCloseLimitHours?: number;

    @IsOptional()
    @IsIn(Object.values(TimeTrackingPolicyAutoCloseMode))
    @Expose()
    autoCloseMode?: TimeTrackingPolicyAutoCloseMode;

    @IsOptional()
    @IsInt()
    @Expose()
    @Min(MIN_AUTO_CLOSE_FIXED_HOURS_VALUE)
    @Max(MAX_AUTO_CLOSE_FIXED_HOURS_VALUE)
    autoCloseFixedHoursValue?: number | null;

    @IsOptional()
    @IsInt()
    @Expose()
    @Min(MIN_AUTO_CLOSE_FIXED_MINUTES_VALUE)
    @Max(MAX_AUTO_CLOSE_FIXED_MINUTES_VALUE)
    autoCloseFixedMinutesValue?: number | null;

    @IsOptional()
    @IsArray()
    @Expose()
    @ValidateNested({ each: true })
    @Type(() => TimeTrackingPolicyHourCategoryForCreationVC)
    policyHourCategories?: TimeTrackingPolicyHourCategoryForCreationVC[];

    @IsOptional()
    @IsBoolean()
    @Expose()
    geofencing?: boolean;

    @IsOptional()
    @IsBoolean()
    @Expose()
    enableRemoteWork?: boolean;

    @IsOptional()
    @IsBoolean()
    @Expose()
    saveRemoteWorkLocation?: boolean;
}
