import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsString,
  IsOptional,
  IsInt,
  IsBoolean,
  IsDateString,
  Matches,
  Min,
  Max,
  ValidateNested,
  IsArray,
} from 'class-validator';
import { Type } from 'class-transformer';

export class ScheduleSlotDto {
  @ApiProperty({ description: 'Day of week (0=Mon, 6=Sun)', example: 0 })
  @IsInt()
  @Min(0)
  @Max(6)
  @Type(() => Number)
  dayOfWeek: number;

  @ApiProperty({ description: 'Start time HH:MM', example: '09:00' })
  @IsString()
  @Matches(/^\d{2}:\d{2}$/)
  startTime: string;

  @ApiProperty({ description: 'End time HH:MM', example: '18:00' })
  @IsString()
  @Matches(/^\d{2}:\d{2}$/)
  endTime: string;

  @ApiPropertyOptional({ description: 'Break start HH:MM', example: '13:00' })
  @IsString()
  @Matches(/^\d{2}:\d{2}$/)
  @IsOptional()
  breakStart?: string;

  @ApiPropertyOptional({ description: 'Break end HH:MM', example: '14:00' })
  @IsString()
  @Matches(/^\d{2}:\d{2}$/)
  @IsOptional()
  breakEnd?: string;

  @ApiPropertyOptional({ default: true })
  @IsBoolean()
  @IsOptional()
  isActive?: boolean;
}

export class SetStaffScheduleDto {
  @ApiProperty({ type: [ScheduleSlotDto], description: 'Weekly schedule slots' })
  @ValidateNested({ each: true })
  @Type(() => ScheduleSlotDto)
  @IsArray()
  slots: ScheduleSlotDto[];
}

export class CreateStaffExceptionDto {
  @ApiProperty({ description: 'Date (YYYY-MM-DD)', example: '2026-03-01' })
  @IsDateString()
  date: string;

  @ApiPropertyOptional({
    description: 'Is workday (true = extra day, false = day off)',
    default: false,
  })
  @IsBoolean()
  @IsOptional()
  isWorkday?: boolean;

  @ApiPropertyOptional({ description: 'Start time (if workday)', example: '10:00' })
  @IsString()
  @Matches(/^\d{2}:\d{2}$/)
  @IsOptional()
  startTime?: string;

  @ApiPropertyOptional({ description: 'End time (if workday)', example: '16:00' })
  @IsString()
  @Matches(/^\d{2}:\d{2}$/)
  @IsOptional()
  endTime?: string;

  @ApiPropertyOptional({ description: 'Reason', example: 'Больничный' })
  @IsString()
  @IsOptional()
  reason?: string;
}
