import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsEnum,
  IsString,
  IsOptional,
  IsDateString,
  IsNumber,
  Min,
  MaxLength,
} from 'class-validator';
import { AbsenceType } from '@prisma/client';

export class CreateAbsenceDto {
  @ApiProperty({
    description: 'Type of absence',
    enum: AbsenceType,
    example: AbsenceType.VACATION,
  })
  @IsEnum(AbsenceType)
  type: AbsenceType;

  @ApiProperty({
    description: 'Start date of the absence (ISO 8601 format)',
    example: '2024-03-15',
  })
  @IsDateString()
  startDate: string;

  @ApiProperty({
    description: 'End date of the absence (ISO 8601 format)',
    example: '2024-03-20',
  })
  @IsDateString()
  endDate: string;

  @ApiPropertyOptional({
    description: 'Number of days (calculated automatically if not provided)',
    example: 5,
    minimum: 0.5,
  })
  @IsOptional()
  @IsNumber()
  @Min(0.5)
  days?: number;

  @ApiPropertyOptional({
    description: 'Optional note or reason for the absence',
    example: 'Family vacation',
    maxLength: 1000,
  })
  @IsOptional()
  @IsString()
  @MaxLength(1000)
  note?: string;

  @ApiPropertyOptional({
    description: 'Employee ID (required for managers creating absences for others)',
    example: 'clq1234567890abcdef',
  })
  @IsOptional()
  @IsString()
  employeeId?: string;
}
