import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { IsDateString, IsEnum, IsOptional, IsString, IsUUID, MaxLength, MinLength, ValidateIf, } from 'class-validator'; import { CardInstanceStatutType, CardOperationType } from 'src/entities/card_instances.entity'; import { CardResponseActionType } from 'src/entities/card_responses.entity'; export class CreerCarteDto { @ApiProperty({ description: 'absence_enfant | absence_enfant_modif | conge_am | arret_maladie_am', }) @IsString() type_code: string; @ApiProperty() @IsUUID() id_placement: string; @ApiProperty({ example: '2026-10-01' }) @IsDateString() date_debut: string; @ApiProperty({ example: '2026-10-05' }) @IsDateString() date_fin: string; @ApiPropertyOptional() @IsOptional() @IsString() @MaxLength(2000) motif?: string; @ApiPropertyOptional({ description: 'Requis pour operation=update (même id absences_garde)', }) @IsOptional() @IsUUID() id_absence?: string; @ApiPropertyOptional({ enum: CardOperationType, default: CardOperationType.CREATE }) @IsOptional() @IsEnum(CardOperationType) operation?: CardOperationType; } export class RepondreCarteDto { @ApiProperty({ enum: CardResponseActionType }) @IsEnum(CardResponseActionType) action: CardResponseActionType; @ApiPropertyOptional({ description: 'Obligatoire si action=refuse' }) @ValidateIf((o) => o.action === CardResponseActionType.REFUSE) @IsString() @MinLength(1) @MaxLength(2000) comment?: string; } export class MajCarteDto { @ApiPropertyOptional() @IsOptional() @IsDateString() date_debut?: string; @ApiPropertyOptional() @IsOptional() @IsDateString() date_fin?: string; @ApiPropertyOptional() @IsOptional() @IsString() @MaxLength(2000) motif?: string; } export class CarteDto { @ApiProperty() id: string; @ApiProperty() type_code: string; @ApiProperty() titre: string; @ApiPropertyOptional() couleur?: string | null; @ApiProperty() id_placement: string; @ApiPropertyOptional() id_absence?: string | null; @ApiProperty({ enum: CardOperationType }) operation: CardOperationType; @ApiProperty({ enum: CardInstanceStatutType }) statut: CardInstanceStatutType; @ApiProperty() payload: Record; @ApiProperty() purge_at: string; @ApiPropertyOptional() cree_par?: string | null; @ApiProperty() is_creator: boolean; @ApiPropertyOptional() response_mode?: string; @ApiPropertyOptional() last_refuse_comment?: string | null; @ApiProperty() cree_le: string; @ApiProperty() modifie_le: string; } export class ListeCartesDto { @ApiProperty({ type: [CarteDto] }) items: CarteDto[]; }