import {
  IsString,
  IsUUID,
  IsOptional,
  IsDateString,
  IsEnum,
  IsBoolean,
  IsNumber,
  Min,
} from 'class-validator';
import { EmployeeStatus } from '../entities/employee.entity';
import { ContractStatus, ContractType } from '../entities/contract.entity';
import { LeaveStatus } from '../entities/leave.entity';
import { LeaveTypeCategory } from '../entities/leave-type.entity';

/**
 * Filters for querying employees
 */
export class EmployeeFiltersDto {
  @IsOptional()
  @IsUUID()
  companyId?: string;

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

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

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

  @IsOptional()
  @IsEnum(['active', 'inactive', 'on_leave', 'terminated'])
  status?: EmployeeStatus;

  @IsOptional()
  @IsBoolean()
  hasUser?: boolean;

  @IsOptional()
  @IsString()
  search?: string;

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

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

/**
 * Filters for querying departments
 */
export class DepartmentFiltersDto {
  @IsOptional()
  @IsUUID()
  companyId?: string;

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

  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

  @IsOptional()
  @IsBoolean()
  isRoot?: boolean;

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

/**
 * Filters for querying job positions
 */
export class JobPositionFiltersDto {
  @IsOptional()
  @IsUUID()
  companyId?: string;

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

  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

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

/**
 * Filters for querying contracts
 */
export class ContractFiltersDto {
  @IsOptional()
  @IsUUID()
  companyId?: string;

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

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

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

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

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

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

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

  @IsOptional()
  @IsBoolean()
  expiringWithinDays?: number;

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

/**
 * Filters for querying leave types
 */
export class LeaveTypeFiltersDto {
  @IsOptional()
  @IsUUID()
  companyId?: string;

  @IsOptional()
  @IsEnum(['vacation', 'sick', 'personal', 'maternity', 'paternity', 'bereavement', 'unpaid', 'other'])
  leaveCategory?: LeaveTypeCategory;

  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

  @IsOptional()
  @IsBoolean()
  isPaid?: boolean;

  @IsOptional()
  @IsBoolean()
  requiresApproval?: boolean;

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

/**
 * Filters for querying leaves
 */
export class LeaveFiltersDto {
  @IsOptional()
  @IsUUID()
  companyId?: string;

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

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

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

  @IsOptional()
  @IsEnum(['draft', 'submitted', 'approved', 'rejected', 'cancelled'])
  status?: LeaveStatus;

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

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

  @IsOptional()
  @IsBoolean()
  pendingApproval?: boolean;

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

/**
 * Filters for querying leave allocations
 */
export class LeaveAllocationFiltersDto {
  @IsOptional()
  @IsUUID()
  employeeId?: string;

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

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

  @IsOptional()
  @IsBoolean()
  hasRemainingDays?: boolean;
}

/**
 * Pagination parameters for HR queries
 */
export class HrPaginationDto {
  @IsOptional()
  @IsNumber()
  @Min(1)
  page?: number;

  @IsOptional()
  @IsNumber()
  @Min(1)
  limit?: number;

  @IsOptional()
  @IsString()
  sortBy?: string;

  @IsOptional()
  @IsEnum(['asc', 'desc', 'ASC', 'DESC'])
  sortOrder?: 'asc' | 'desc' | 'ASC' | 'DESC';
}
