import { ISO_DATE } from '@humand-packages/common';
import { Expose, Type } from 'class-transformer';
import { ArrayMaxSize, ArrayMinSize, IsArray, IsIn, IsNumber, IsOptional, IsString, ValidateIf, ValidateNested } from 'class-validator';
import { IsValidDate } from '../../../../middlewares/dateValidator';
import { GROUP_MEMBER_POLICIES } from '../../../regions/business/types/regions';
import { ScheduledDayVC } from './scheduledDayVC';
import { TimeSlotVC } from './timeSlotVC';

export class UpdateWorkScheduleVC {
    @IsOptional()
    @IsString()
    @Expose()
    name?: string;

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

    @IsOptional()
    @IsArray()
    @ArrayMaxSize(7)
    @ArrayMinSize(1)
    @ValidateNested({ each: true })
    @Type(() => ScheduledDayVC)
    @Expose()
    scheduledDays?: ScheduledDayVC[];

    @IsOptional()
    @IsArray()
    @ArrayMaxSize(4)
    @ArrayMinSize(1)
    @ValidateNested({ each: true })
    @Type(() => TimeSlotVC)
    @Expose()
    generalTimeSlots?: TimeSlotVC[];

    @IsOptional()
    @IsIn(Object.values(GROUP_MEMBER_POLICIES))
    @IsString()
    @Expose()
    userMode?: string;

    @ValidateIf((params: UpdateWorkScheduleVC) => params.userMode === GROUP_MEMBER_POLICIES.TARGETED_USERS)
    @IsArray()
    @ArrayMinSize(1)
    @IsNumber({}, { each: true })
    @Expose()
    collaborators?: number[];

    @IsOptional()
    @IsString()
    @IsValidDate(ISO_DATE)
    @Expose()
    startDate?: string;

    @IsOptional()
    @IsString()
    @IsValidDate(ISO_DATE)
    @Expose()
    endDate?: string;
}
