import { ApiProperty, 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';

export class BankAccountDto {
  @ApiProperty({
    description: 'IBAN of the bank account',
    example: 'DE89370400440532013000',
  })
  @IsString()
  @MinLength(15)
  @MaxLength(34)
  iban: string;

  @ApiPropertyOptional({
    description: 'BIC/SWIFT code',
    example: 'COBADEFFXXX',
  })
  @IsOptional()
  @IsString()
  @MaxLength(11)
  bic?: string;

  @ApiPropertyOptional({
    description: 'Bank name',
    example: 'Commerzbank',
  })
  @IsOptional()
  @IsString()
  @MaxLength(100)
  bankName?: string;

  @ApiPropertyOptional({
    description: 'Account holder name',
    example: 'Max Mustermann',
  })
  @IsOptional()
  @IsString()
  @MaxLength(100)
  accountHolder?: string;
}

export class CreateEmployeeDto {
  @ApiProperty({
    description: 'User ID to link this employee record to',
    example: 'clq1234567890abcdef',
  })
  @IsString()
  userId: string;

  @ApiProperty({
    description: 'Unique employee number',
    example: 'EMP-2024-001',
  })
  @IsString()
  @MinLength(1)
  @MaxLength(50)
  employeeNumber: string;

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

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

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

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

  @ApiPropertyOptional({
    description: 'Weekly working hours',
    example: 40,
    minimum: 0,
    maximum: 60,
    default: 40,
  })
  @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,
    default: true,
  })
  @IsOptional()
  @IsBoolean()
  isActive?: boolean;
}
