import { DefaultValue, 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 CreateWorkScheduleVC {
    @IsOptional()
    @IsString()
    @Expose()
    name?: string;

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

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

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

    @DefaultValue(GROUP_MEMBER_POLICIES.NONE)
    @IsIn(Object.values(GROUP_MEMBER_POLICIES))
    @IsString()
    @Expose()
    userMode!: string;

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

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

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