// Phase 10.3-10.4 Workflow Apps types (S38 — Mig 39+40 skeleton).
// Skeleton Phase 1: Status flat 5-state + List read-only. Create defer Phase 11.
// File MIRROR SHA256 identical fe-user counterpart.

export const WorkflowAppStatus = {
  Nhap: 1,
  DaGuiDuyet: 2,
  TraLai: 3,
  TuChoi: 4,
  DaDuyet: 5,
} as const

export const WORKFLOW_APP_STATUS_LABELS: Record<number, string> = {
  1: 'Nháp', 2: 'Đã gửi duyệt', 3: 'Trả lại', 4: 'Từ chối', 5: 'Đã duyệt',
}

export const WORKFLOW_APP_STATUS_BADGE: Record<number, string> = {
  1: 'bg-slate-100 text-slate-700 border-slate-300',
  2: 'bg-amber-100 text-amber-800 border-amber-300',
  3: 'bg-orange-100 text-orange-800 border-orange-300',
  4: 'bg-red-100 text-red-800 border-red-300',
  5: 'bg-emerald-100 text-emerald-800 border-emerald-300',
}

export const ItTicketCategory = {
  Hardware: 1, Software: 2, Network: 3, Account: 4, Other: 99,
} as const
export const IT_TICKET_CATEGORY_LABELS: Record<number, string> = {
  1: 'Phần cứng', 2: 'Phần mềm', 3: 'Mạng', 4: 'Tài khoản', 99: 'Khác',
}

export const ItTicketPriority = { Low: 1, Medium: 2, High: 3, Urgent: 4 } as const
export const IT_TICKET_PRIORITY_LABELS: Record<number, string> = {
  1: 'Thấp', 2: 'TB', 3: 'Cao', 4: 'Khẩn',
}
export const IT_TICKET_PRIORITY_BADGE: Record<number, string> = {
  1: 'bg-slate-100 text-slate-700', 2: 'bg-blue-100 text-blue-800',
  3: 'bg-amber-100 text-amber-800', 4: 'bg-red-100 text-red-800',
}

export const ItTicketStatus = { Open: 1, InProgress: 2, Resolved: 3, Closed: 4, Reopened: 5 } as const
export const IT_TICKET_STATUS_LABELS: Record<number, string> = {
  1: 'Mới', 2: 'Đang xử lý', 3: 'Đã giải quyết', 4: 'Đã đóng', 5: 'Mở lại',
}

// Phase 11 P11-A Wave 3a (S42 2026-05-30) — Detail + LevelOpinion shape cho 4 module
// (leave/ot/travel/vehicle) mirror BE LeaveOt/TravelVehicleApprovalFeatures DetailDto.
export interface WorkflowAppLevelOpinion {
  id: string
  approvalWorkflowLevelId: string
  stepOrder: number | null
  stepName: string | null
  levelOrder: number | null
  approverUserId: string | null
  comment: string | null
  signedAt: string
  signedByUserId: string
  signedByFullName: string
}

// Superset detail — module-specific fields optional, rendered theo KIND_CONFIG.detailFields.
export interface WorkflowAppDetail {
  id: string
  maDonTu: string | null
  requesterUserId: string
  requesterFullName: string
  status: number
  approvalWorkflowId: string | null
  workflowCode: string | null
  workflowName: string | null
  currentApprovalLevelOrder: number | null
  rejectedFromStatus: number | null
  createdAt: string
  levelOpinions: WorkflowAppLevelOpinion[]
  // leave
  leaveTypeId?: string
  startDate?: string
  endDate?: string
  numDays?: number
  reason?: string
  // leave balance (P11-B Wave 1: embed số dư phép NGƯỜI TẠO cho loại phép + năm đơn; null nếu loại phép không tồn tại)
  leaveBalanceEntitled?: number | null
  leaveBalanceUsed?: number | null
  leaveBalanceRemaining?: number | null
  // ot
  otDate?: string
  startTime?: string
  endTime?: string
  hours?: number
  otPolicyId?: string | null
  // travel
  destination?: string
  purpose?: string
  estimatedCost?: number | null
  // vehicle
  vehicleLicense?: string
  vehicleName?: string | null
  startAt?: string
  endAt?: string
  driverName?: string | null
}

export interface PagedResult<T> {
  items: T[]
  total: number
  page: number
  pageSize: number
  totalPages: number
  hasNext: boolean
  hasPrev: boolean
}

export interface LeaveRequestDto { id: string; maDonTu: string | null; requesterUserId: string; requesterFullName: string; leaveTypeId: string; startDate: string; endDate: string; numDays: number; reason: string; status: number; approvalWorkflowId: string | null; currentApprovalLevelOrder: number | null; createdAt: string }
export interface OtRequestDto { id: string; maDonTu: string | null; requesterUserId: string; requesterFullName: string; otDate: string; startTime: string; endTime: string; hours: number; reason: string; otPolicyId: string | null; status: number; approvalWorkflowId: string | null; currentApprovalLevelOrder: number | null; createdAt: string }
export interface TravelRequestDto { id: string; maDonTu: string | null; requesterUserId: string; requesterFullName: string; destination: string; startDate: string; endDate: string; numDays: number; purpose: string; estimatedCost: number | null; status: number; approvalWorkflowId: string | null; currentApprovalLevelOrder: number | null; createdAt: string }
export interface VehicleBookingDto { id: string; maDonTu: string | null; requesterUserId: string; requesterFullName: string; vehicleLicense: string; vehicleName: string | null; startAt: string; endAt: string; destination: string; purpose: string; driverName: string | null; status: number; approvalWorkflowId: string | null; currentApprovalLevelOrder: number | null; createdAt: string }
export interface ItTicketDto { id: string; maTicket: string | null; requesterUserId: string; requesterFullName: string; title: string; description: string; category: number; priority: number; status: number; assignedToUserId: string | null; assignedToFullName: string | null; resolvedAt: string | null; resolution: string | null; createdAt: string; slaDueAt: string | null; slaBreached: boolean }
// S54 — reassign capability flag từ BE GET /it-tickets/assignable-staff (Admin OR tổ IT). canReassign=false + staff=[] cho user thường.
export type AssignableStaff = { id: string; fullName: string }
export type AssignableStaffResult = { canReassign: boolean; staff: AssignableStaff[] }
export interface AttendanceDto { id: string; userId: string; userFullName: string; attendanceDate: string; checkInAt: string | null; checkOutAt: string | null; sourceIn: number; sourceOut: number; checkInLatitude: number | null; checkInLongitude: number | null; workHours: number | null; otHours: number | null; note: string | null }
export interface HrDashboardDto { totalEmployees: number; activeEmployees: number; onLeaveEmployees: number; resignedEmployees: number; maleCount: number; femaleCount: number; birthdaysThisWeek: number; newHiresThisMonth: number }
