import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { ArrayMaxSize, ArrayMinSize, ArrayUnique, IsArray, IsDateString, IsNotEmpty, IsOptional, IsString, Matches, MaxLength, } from 'class-validator'; export const MAX_RESTRICTION_APIARIES = 50; const MAX_ID_LENGTH = 64; const MAX_TEXT_LENGTH = 200; const MAX_NOTE_LENGTH = 2000; const ID_PATTERN = /^[A-Za-z0-9_-]+$/; const DAY_PATTERN = /^\d{4}-\d{2}-\d{2}$/; const DAY_MESSAGE = 'muss ein Datum im Format JJJJ-MM-TT sein'; /** A restricted zone declared by the authority, for one or several apiaries. */ export class CreateApiaryRestrictionDto { @ApiProperty({ type: [String], description: 'Ein Datensatz je Stand, 1 bis 50 Stände', }) @IsArray() @ArrayMinSize(1) @ArrayMaxSize(MAX_RESTRICTION_APIARIES) @ArrayUnique() @IsString({ each: true }) @Matches(ID_PATTERN, { each: true }) @MaxLength(MAX_ID_LENGTH, { each: true }) apiaryIds!: string[]; @ApiProperty({ description: 'Seuche, z. B. Amerikanische Faulbrut' }) @IsString() @IsNotEmpty() @Matches(/\S/, { message: 'disease darf nicht nur aus Leerzeichen bestehen' }) @MaxLength(MAX_TEXT_LENGTH) disease!: string; @ApiPropertyOptional({ nullable: true, description: 'Anordnende Behörde' }) @IsOptional() @IsString() @MaxLength(MAX_TEXT_LENGTH) authority?: string | null; @ApiPropertyOptional({ nullable: true, description: 'Aktenzeichen' }) @IsOptional() @IsString() @MaxLength(MAX_TEXT_LENGTH) reference?: string | null; @ApiProperty({ example: '2026-10-01', description: 'Erster Tag der Sperre' }) @Matches(DAY_PATTERN, { message: `startsOn ${DAY_MESSAGE}` }) @IsDateString({ strict: true }) startsOn!: string; @ApiPropertyOptional({ nullable: true, example: '2026-12-01', description: 'Letzter Tag der Sperre; leer = bis auf Weiteres', }) @IsOptional() @Matches(DAY_PATTERN, { message: `endsOn ${DAY_MESSAGE}` }) @IsDateString({ strict: true }) endsOn?: string | null; @ApiPropertyOptional({ nullable: true }) @IsOptional() @IsString() @MaxLength(MAX_NOTE_LENGTH) notes?: string | null; }