// Types cho module Hồ sơ Nhân sự (HRM) — mirror BE Domain.Hrm.Enums + DTOs.
// Phase 10.1 G-H1 (S33) — Pattern 12-bis cross-module FE port PE → Hrm (4th
// reinforcement). TS6 erasableSyntaxOnly cấm enum → const-object pattern bắt buộc.

// ========== Enum mirror BE Domain.Hrm.Enums (10 enum) ==========

export const EmployeeStatus = {
  Active: 1,
  OnLeave: 2,
  Resigned: 3,
} as const
export type EmployeeStatus = typeof EmployeeStatus[keyof typeof EmployeeStatus]

export const EmployeeStatusLabel: Record<number, string> = {
  1: 'Đang làm việc',
  2: 'Nghỉ phép',
  3: 'Đã nghỉ việc',
}

export const EmployeeStatusColor: Record<number, string> = {
  1: 'bg-emerald-100 text-emerald-700',
  2: 'bg-amber-100 text-amber-700',
  3: 'bg-slate-100 text-slate-600',
}

export const Gender = {
  Male: 1,
  Female: 2,
  Other: 3,
} as const
export type Gender = typeof Gender[keyof typeof Gender]

export const GenderLabel: Record<number, string> = {
  1: 'Nam',
  2: 'Nữ',
  3: 'Khác',
}

export const MaritalStatus = {
  Single: 1,
  Married: 2,
  Divorced: 3,
  Widowed: 4,
} as const
export type MaritalStatus = typeof MaritalStatus[keyof typeof MaritalStatus]

export const MaritalStatusLabel: Record<number, string> = {
  1: 'Độc thân',
  2: 'Đã kết hôn',
  3: 'Đã ly hôn',
  4: 'Goá',
}

export const EmployeeType = {
  FullTime: 1,
  PartTime: 2,
  Intern: 3,
  Contractor: 4,
} as const
export type EmployeeType = typeof EmployeeType[keyof typeof EmployeeType]

export const EmployeeTypeLabel: Record<number, string> = {
  1: 'Chính thức',
  2: 'Bán thời gian',
  3: 'Thực tập',
  4: 'Khoán việc',
}

export const DegreeLevel = {
  College: 1,
  Bachelor: 2,
  Master: 3,
  PhD: 4,
} as const
export type DegreeLevel = typeof DegreeLevel[keyof typeof DegreeLevel]

export const DegreeLevelLabel: Record<number, string> = {
  1: 'Cao đẳng',
  2: 'Đại học',
  3: 'Thạc sĩ',
  4: 'Tiến sĩ',
}

export const EducationMode = {
  FullTime: 1,
  PartTime: 2,
  Distance: 3,
} as const
export type EducationMode = typeof EducationMode[keyof typeof EducationMode]

export const EducationModeLabel: Record<number, string> = {
  1: 'Chính quy',
  2: 'Tại chức',
  3: 'Từ xa',
}

export const GradeLevel = {
  Average: 1,
  Good: 2,
  Excellent: 3,
} as const
export type GradeLevel = typeof GradeLevel[keyof typeof GradeLevel]

export const GradeLevelLabel: Record<number, string> = {
  1: 'Trung bình',
  2: 'Khá',
  3: 'Giỏi',
}

export const FamilyRelationKind = {
  Father: 1,
  Mother: 2,
  Spouse: 3,
  Child: 4,
  Sibling: 5,
  Other: 99,
} as const
export type FamilyRelationKind = typeof FamilyRelationKind[keyof typeof FamilyRelationKind]

export const FamilyRelationKindLabel: Record<number, string> = {
  1: 'Cha',
  2: 'Mẹ',
  3: 'Vợ/Chồng',
  4: 'Con',
  5: 'Anh/Chị/Em ruột',
  99: 'Khác',
}

export const SkillKind = {
  Computer: 1,
  Language: 2,
  Other: 3,
} as const
export type SkillKind = typeof SkillKind[keyof typeof SkillKind]

export const SkillKindLabel: Record<number, string> = {
  1: 'Kỹ năng vi tính',
  2: 'Ngoại ngữ',
  3: 'Kỹ năng khác',
}

export const EmployeeDocumentType = {
  IdCard: 1,
  Passport: 2,
  Degree: 3,
  Certificate: 4,
  LaborContract: 5,
  Other: 99,
} as const
export type EmployeeDocumentType = typeof EmployeeDocumentType[keyof typeof EmployeeDocumentType]

export const EmployeeDocumentTypeLabel: Record<number, string> = {
  1: 'CMND/CCCD',
  2: 'Hộ chiếu',
  3: 'Bằng cấp',
  4: 'Chứng chỉ',
  5: 'HĐLĐ',
  99: 'Khác',
}

// ========== List item (paged) ==========

export type EmployeeListItem = {
  id: string
  employeeCode: string
  userId: string
  fullName: string | null
  email: string | null
  departmentId: string | null
  departmentName: string | null
  status: number
  phone: string | null
  hireDate: string | null
  createdAt: string
  updatedAt: string | null
}

// ========== Satellite read DTOs (inline GetDetail bundle) ==========

export type EmployeeWorkHistoryDto = {
  id: string
  companyName: string
  companyAddress: string | null
  industry: string | null
  fromDate: string | null
  toDate: string | null
  jobTitle: string | null
  jobDescription: string | null
  resignReason: string | null
}

export type EmployeeEducationDto = {
  id: string
  schoolName: string
  major: string | null
  degreeLevel: number | null
  educationMode: number | null
  gradeLevel: number | null
  fromDate: string | null
  toDate: string | null
  certificateIssueDate: string | null
  notes: string | null
}

export type EmployeeFamilyRelationDto = {
  id: string
  fullName: string
  relationship: number
  birthYear: number | null
  occupation: string | null
  currentAddress: string | null
  phone: string | null
}

export type EmployeeSkillDto = {
  id: string
  kind: number
  name: string
  languageId: string | null
  level: string | null
}

export type EmployeeDocumentDto = {
  id: string
  documentType: number
  fileName: string
  filePath: string
  fileSize: number
  contentType: string
  issueDate: string | null
  expiryDate: string | null
  notes: string | null
}

// ========== Satellite Create/Update Input Commands (S35 Plan B-WrapPlus1) ==========
// Mirror BE record Command field shape (EmployeeSatelliteFeatures.cs). UpdateInput
// reuse CreateInput shape (DRY) — handler set `id` separately at API call site.

export type CreateEmployeeWorkHistoryInput = {
  companyName: string
  companyAddress: string | null
  industry: string | null
  fromDate: string | null
  toDate: string | null
  jobTitle: string | null
  jobDescription: string | null
  resignReason: string | null
}

export type CreateEmployeeEducationInput = {
  schoolName: string
  major: string | null
  degreeLevel: number | null
  educationMode: number | null
  gradeLevel: number | null
  fromDate: string | null
  toDate: string | null
  certificateIssueDate: string | null
  notes: string | null
}

export type CreateEmployeeFamilyRelationInput = {
  fullName: string
  relationship: number
  birthYear: number | null
  occupation: string | null
  currentAddress: string | null
  phone: string | null
}

export type CreateEmployeeSkillInput = {
  kind: number
  name: string
  languageId: string | null
  level: string | null
}

export type CreateEmployeeDocumentInput = {
  documentType: number
  fileName: string
  filePath: string
  fileSize: number
  contentType: string
  issueDate: string | null
  expiryDate: string | null
  notes: string | null
}

// ========== Detail (full + 5 satellite collection) ==========

export type EmployeeDetail = {
  id: string
  employeeCode: string
  userId: string
  fullName: string | null
  email: string | null
  departmentId: string | null
  departmentName: string | null
  employeeStatus: number
  gender: number | null
  maritalStatus: number | null
  employeeType: number | null
  dateOfBirth: string | null
  birthPlace: string | null
  hometown: string | null
  phone: string | null
  personalEmail: string | null
  internalPhone: string | null
  ethnicity: string | null
  religion: string | null
  nationality: string | null
  idCardNumber: string | null
  idCardIssueDate: string | null
  idCardIssuePlace: string | null
  taxCode: string | null
  socialInsuranceNumber: string | null
  passportNumber: string | null
  permanentAddressText: string | null
  streetAddressPermanent: string | null
  temporaryAddressText: string | null
  streetAddressTemporary: string | null
  hireDate: string | null
  resignDate: string | null
  emergencyContactName: string | null
  emergencyContactPhone: string | null
  emergencyContactAddress: string | null
  qualification: string | null
  academicTitle: string | null
  workLocation: string | null
  timekeepingCode: string | null
  bankAccount: string | null
  bankName: string | null
  bankBranch: string | null
  heightCm: number | null
  weightKg: number | null
  bloodType: string | null
  baseSalary: number | null
  totalSalary: number | null
  annualLeaveDays: number | null
  remainingLeaveDays: number | null
  compensatoryLeaveDays: number | null
  seniorityLeaveDays: number | null
  socialInsuranceStartDate: string | null
  medicalRegistrationPlace: string | null
  isCommunistParty: boolean
  communistPartyJoinDate: string | null
  isYouthUnion: boolean
  youthUnionJoinDate: string | null
  isTradeUnion: boolean
  tradeUnionJoinDate: string | null
  photoUrl: string | null
  notes: string | null
  createdAt: string
  updatedAt: string | null
  workHistories: EmployeeWorkHistoryDto[]
  educations: EmployeeEducationDto[]
  familyRelations: EmployeeFamilyRelationDto[]
  skills: EmployeeSkillDto[]
  documents: EmployeeDocumentDto[]
}
