import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsString,
  IsOptional,
  IsDate,
  IsEnum,
  IsInt,
  Min,
  Max,
  MaxLength,
} from 'class-validator';
import { Type } from 'class-transformer';
import { TimeEntryType } from '@prisma/client';

export class CreateTimeEntryDto {
  @ApiProperty({
    description: 'Employee ID for the time entry',
    example: 'clq1234567890abcdef',
  })
  @IsString()
  employeeId: string;

  @ApiProperty({
    description: 'Date of the time entry',
    example: '2024-01-15',
  })
  @Type(() => Date)
  @IsDate()
  date: Date;

  @ApiPropertyOptional({
    description: 'Clock-in time',
    example: '2024-01-15T08:00:00.000Z',
  })
  @IsOptional()
  @Type(() => Date)
  @IsDate()
  clockIn?: Date;

  @ApiPropertyOptional({
    description: 'Clock-out time',
    example: '2024-01-15T17:00:00.000Z',
  })
  @IsOptional()
  @Type(() => Date)
  @IsDate()
  clockOut?: Date;

  @ApiPropertyOptional({
    description: 'Total break time in minutes',
    example: 45,
    minimum: 0,
    maximum: 480,
    default: 0,
  })
  @IsOptional()
  @IsInt()
  @Min(0)
  @Max(480)
  breakMinutes?: number;

  @ApiPropertyOptional({
    description: 'Type of time entry',
    enum: TimeEntryType,
    example: TimeEntryType.REGULAR,
    default: TimeEntryType.REGULAR,
  })
  @IsOptional()
  @IsEnum(TimeEntryType)
  type?: TimeEntryType;

  @ApiPropertyOptional({
    description: 'Note or reason for the entry (especially for corrections)',
    example: 'Manual entry: Forgot to clock in',
    maxLength: 500,
  })
  @IsOptional()
  @IsString()
  @MaxLength(500)
  note?: string;
}
