import {
  IsString,
  IsUUID,
  IsOptional,
  IsDateString,
  IsEnum,
  IsNumber,
  IsPositive,
  MaxLength,
  MinLength,
  Min,
  Max,
} from 'class-validator';
import { ContractType, ContractStatus, WageType } from '../entities/contract.entity';

/**
 * DTO for creating a new employment contract
 */
export class CreateContractDto {
  @IsUUID()
  companyId: string;

  @IsUUID()
  employeeId: string;

  @IsString()
  @MinLength(1)
  @MaxLength(255)
  name: string;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  reference?: string;

  @IsOptional()
  @IsEnum(['permanent', 'temporary', 'contractor', 'internship', 'part_time'])
  contractType?: ContractType;

  @IsOptional()
  @IsEnum(['draft', 'active', 'expired', 'terminated', 'cancelled'])
  status?: ContractStatus;

  @IsDateString()
  dateStart: string;

  @IsOptional()
  @IsDateString()
  dateEnd?: string;

  @IsOptional()
  @IsUUID()
  jobPositionId?: string;

  @IsOptional()
  @IsUUID()
  departmentId?: string;

  // Compensation
  @IsNumber()
  @IsPositive()
  wage: number;

  @IsOptional()
  @IsEnum(['hourly', 'daily', 'weekly', 'biweekly', 'monthly', 'annual'])
  wageType?: WageType;

  @IsOptional()
  @IsString()
  @MaxLength(3)
  currency?: string;

  // Schedule
  @IsOptional()
  @IsNumber()
  @Min(0)
  @Max(168)
  hoursPerWeek?: number;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  scheduleType?: string;

  // Trial period
  @IsOptional()
  @IsNumber()
  @Min(0)
  @Max(12)
  trialPeriodMonths?: number;

  @IsOptional()
  @IsDateString()
  trialDateEnd?: string;

  // Metadata
  @IsOptional()
  @IsString()
  notes?: string;

  @IsOptional()
  @IsString()
  documentUrl?: string;
}

/**
 * DTO for updating an existing contract
 */
export class UpdateContractDto {
  @IsOptional()
  @IsString()
  @MinLength(1)
  @MaxLength(255)
  name?: string;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  reference?: string | null;

  @IsOptional()
  @IsEnum(['permanent', 'temporary', 'contractor', 'internship', 'part_time'])
  contractType?: ContractType;

  @IsOptional()
  @IsEnum(['draft', 'active', 'expired', 'terminated', 'cancelled'])
  status?: ContractStatus;

  @IsOptional()
  @IsDateString()
  dateStart?: string;

  @IsOptional()
  @IsDateString()
  dateEnd?: string | null;

  @IsOptional()
  @IsUUID()
  jobPositionId?: string | null;

  @IsOptional()
  @IsUUID()
  departmentId?: string | null;

  // Compensation
  @IsOptional()
  @IsNumber()
  @IsPositive()
  wage?: number;

  @IsOptional()
  @IsEnum(['hourly', 'daily', 'weekly', 'biweekly', 'monthly', 'annual'])
  wageType?: WageType;

  @IsOptional()
  @IsString()
  @MaxLength(3)
  currency?: string;

  // Schedule
  @IsOptional()
  @IsNumber()
  @Min(0)
  @Max(168)
  hoursPerWeek?: number | null;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  scheduleType?: string | null;

  // Trial period
  @IsOptional()
  @IsNumber()
  @Min(0)
  @Max(12)
  trialPeriodMonths?: number | null;

  @IsOptional()
  @IsDateString()
  trialDateEnd?: string | null;

  // Metadata
  @IsOptional()
  @IsString()
  notes?: string | null;

  @IsOptional()
  @IsString()
  documentUrl?: string | null;

  // Termination (only for termination flow)
  @IsOptional()
  @IsString()
  terminationReason?: string;
}

/**
 * DTO for activating a contract
 */
export class ActivateContractDto {
  @IsOptional()
  @IsDateString()
  activatedAt?: string;
}

/**
 * DTO for terminating a contract
 */
export class TerminateContractDto {
  @IsString()
  @MinLength(1)
  terminationReason: string;

  @IsOptional()
  @IsDateString()
  terminatedAt?: string;
}
