export interface ApiResponse<T> {
  success: boolean
  data: T
  error: { code: string; message: string } | null
}

export interface PaginatedData<T> {
  items: T[]
  total: number
  page: number
  pageSize: number
}

export interface Organization {
  id: string
  name: string
  plan: 'FREE' | 'PRO' | 'ENTERPRISE'
  maxEmployees: number
  city: string | null
}

export interface User {
  id: string
  orgId: string
  name: string
  phone: string
  email: string | null
  role: 'ADMIN' | 'HR' | 'VIEWER'
}

export interface Employee {
  id: string
  orgId: string
  name: string
  department: string
  hireDate: string
  monthlySalary: string
  status: 'ACTIVE' | 'RESIGNED'
  gender: string | null
  phone: string | null
  isPregnant: boolean
  isInMedicalPeriod: boolean
  isWorkInjured: boolean
  contracts: LaborContract[]
}

export interface LaborContract {
  id: string
  employeeId: string
  signDate: string | null
  startDate: string
  endDate: string | null
  contractType: 'FIXED' | 'UNFIXED' | 'UNSIGNED'
  signMethod: 'PAPER' | 'ELECTRONIC'
  contractYears: number
  probationMonths: number
  probationSalary: number
  renewalCount: number
  attachmentName: string | null
  attachmentUrl: string | null
  electronicContractNo: string | null
  electronicContractUrl: string | null
}

export interface RiskItem {
  id: string
  orgId: string
  employeeId: string | null
  type: 'CONTRACT' | 'SALARY' | 'TERMINATION'
  level: 'HIGH' | 'MEDIUM' | 'LOW'
  status: 'PENDING' | 'RESOLVED' | 'IGNORED'
  title: string
  description: string
  actionUrl: string | null
  createdAt: string
}

export interface DashboardData {
  greeting: string
  stats: {
    employeeCount: number
    highRiskCount: number
    todoCount: number
    monthlyOvertimePay: number
  }
  urgentRisk: {
    id: string
    type: 'CONTRACT' | 'SALARY' | 'TERMINATION' | 'MONTHLY' | 'ONBOARDING' | 'RETIREMENT'
    level: 'high' | 'medium' | 'low'
    priority: 'URGENT' | 'HIGH' | 'MEDIUM' | 'LOW'
    title: string
    description: string
    actionUrl: string
    estimatedLoss: number
    lossRange: [number, number] | null
    deadline: string | null
    daysUntilDeadline: number | null
  } | null
  todos: {
    id: string
    type: 'CONTRACT' | 'SALARY' | 'TERMINATION' | 'MONTHLY' | 'ONBOARDING' | 'RETIREMENT'
    level: 'high' | 'medium' | 'low'
    priority: 'URGENT' | 'HIGH' | 'MEDIUM' | 'LOW'
    title: string
    description: string
    actionUrl: string
    estimatedLoss: number
    lossRange: [number, number] | null
    lossReason: string | null
    deadline: string | null
    daysUntilDeadline: number | null
    employeeName: string | null
    employeeDepartment: string | null
  }[]
  resolvedTodos: {
    id: string
    type: 'CONTRACT' | 'SALARY' | 'TERMINATION' | 'MONTHLY' | 'ONBOARDING' | 'RETIREMENT'
    level: 'high' | 'medium' | 'low'
    title: string
    description: string
    actionUrl: string
    resolvedAt: string | null
  }[]
  riskDistribution: {
    contract: number
    salary: number
    termination: number
    retirement: number
    monthly: number
  }
  riskTrend: {
    thisMonth: number
    lastMonth: number
    change: number
  }
  topRisks: {
    id: string
    type: string
    level: string
    priority: 'URGENT' | 'HIGH' | 'MEDIUM' | 'LOW'
    title: string
    description: string
    employeeName: string | null
    estimatedLoss: number
    deadline: string | null
    daysUntilDeadline: number | null
    actionUrl: string
  }[]
  aiPrediction: {
    risks: unknown[]
    suggestion: string
  } | null
  payrollSummary: {
    month: string
    employeeCount: number
    payslipCount: number
    confirmedPayslips: number
    unconfirmedPayslips: number
    baseSalary: number
    overtimePay: number
    allowance: number
    deduction: number
    totalPay: number
    socialOrg: number
    socialEmp: number
    housingOrg: number
    housingEmp: number
    estimatedTax: number
    severancePay: number
    orgTotalCost: number
    empNetPay: number
  }
  monthlyActivities: {
    month: string
    newContracts: number
    terminations: number
    disciplinaryActions: number
    attendanceRecords: number
    overtimeHours: number
    overtimePay: number
  }
  yearCostSummary: {
    year: string
    totalPay: number
    socialOrg: number
    housingOrg: number
    overtimePay: number
    severancePay: number
    orgTotalCost: number
  }
}

export interface TerminationRecord {
  id: string
  employeeId: string
  employeeName: string
  reason: 'NEGOTIATED' | 'FAULT' | 'NONFAULT' | 'LAYOFF' | 'EXPIRED'
  terminationDate: string
  compensation: number
  riskLevel: 'SAFE' | 'WARNING' | 'DANGER'
  checklist: { item: string; passed: boolean; remark?: string }[]
  createdAt: string
}

export interface Payslip {
  id: string
  month: string
  baseSalary: number
  overtimePay: number
  weekdayOvertimePay: number
  weekendOvertimePay: number
  holidayOvertimePay: number
  totalPay: number
  confirmedAt: string | null
}
