import { ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsString,
  IsOptional,
  IsNumber,
  IsDate,
  IsEnum,
  IsBoolean,
  IsInt,
  Min,
  Max,
  MinLength,
  MaxLength,
  IsObject,
  ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';
import { ContractType } from '@prisma/client';
import { BankAccountDto } from './create-employee.dto';

export class UpdateEmployeeDto {
  @ApiPropertyOptional({
    description: 'Unique employee number',
    example: 'EMP-2024-001',
  })
  @IsOptional()
  @IsString()
  @MinLength(1)
  @MaxLength(50)
  employeeNumber?: string;

  @ApiPropertyOptional({
    description: 'Job position/title',
    example: 'Senior Software Engineer',
  })
  @IsOptional()
  @IsString()
  @MinLength(2)
  @MaxLength(100)
  position?: string;

  @ApiPropertyOptional({
    description: 'Employment start date',
    example: '2024-01-15',
  })
  @IsOptional()
  @Type(() => Date)
  @IsDate()
  entryDate?: Date;

  @ApiPropertyOptional({
    description: 'Employment end date (for terminated employees)',
    example: '2025-12-31',
  })
  @IsOptional()
  @Type(() => Date)
  @IsDate()
  exitDate?: Date;

  @ApiPropertyOptional({
    description: 'Type of employment contract',
    enum: ContractType,
    example: ContractType.FULL_TIME,
  })
  @IsOptional()
  @IsEnum(ContractType)
  contractType?: ContractType;

  @ApiPropertyOptional({
    description: 'Weekly working hours',
    example: 40,
    minimum: 0,
    maximum: 60,
  })
  @IsOptional()
  @IsNumber()
  @Min(0)
  @Max(60)
  workingHours?: number;

  @ApiPropertyOptional({
    description: 'Monthly gross salary in EUR (sensitive - will be encrypted)',
    example: 5000,
  })
  @IsOptional()
  @IsNumber()
  @Min(0)
  salary?: number;

  @ApiPropertyOptional({
    description: 'German tax class (1-6)',
    example: 1,
    minimum: 1,
    maximum: 6,
  })
  @IsOptional()
  @IsInt()
  @Min(1)
  @Max(6)
  taxClass?: number;

  @ApiPropertyOptional({
    description: 'Bank account details (sensitive - will be encrypted)',
    type: BankAccountDto,
  })
  @IsOptional()
  @IsObject()
  @ValidateNested()
  @Type(() => BankAccountDto)
  bankAccount?: BankAccountDto;

  @ApiPropertyOptional({
    description: 'Whether the employee is active',
    example: true,
  })
  @IsOptional()
  @IsBoolean()
  isActive?: boolean;
}
