export interface PayrollPeriod {
  id: string;
  name: string;
  year: number;
  month: number;
  start_date: string;
  end_date: string;
  is_locked: boolean;
  payroll_runs_count?: number;
  created_at: string;
  updated_at: string;
}

export interface PayrollRunSummary {
  employee_count: number;
  total_basic: string;
  total_allowances: string;
  total_gross: string;
  total_taxable_income: string;
  total_tax: string;
  total_ssnit_employee: string;
  total_ssnit_employer: string;
  total_tier2_employee: string;
  total_tier2_employer: string;
  total_pf_employee: string;
  total_pf_employer: string;
  total_statutory: string;
  total_deductions: string;
  total_loan_deductions: string;
  total_attendance_deductions?: string;
  total_all_deductions: string;
  total_net: string;
}

export interface PaymentMethodBreakdown {
  payment_method: 'bank_transfer' | 'cash' | 'cheque';
  count: number;
  total: string;
}

export interface PayrollEntryLine {
  id: string;
  payroll_entry_id: string;
  category:
    | 'allowance'
    | 'deduction'
    | 'statutory'
    | 'tax'
    | 'loan'
    | 'adjustment'
    | 'attendance_deduction';
  type_id: string | null;
  description: string;
  amount: string;
  is_taxable: boolean;
  is_pretax: boolean;
}

export interface PensionBreakdownItem {
  pool_id: string;
  pool_code: string;
  pool_name: string;
  report_group: string;
  report_group_label: string;
  employee_amount: string;
  employer_amount: string;
}

export interface PensionSummaryItem {
  pool_id: string;
  pool_code: string;
  pool_name: string;
  report_group: string;
  report_group_label: string;
  total_employee: string;
  total_employer: string;
}

export interface PayrollEntry {
  id: string;
  payroll_run_id: string;
  employee_id: string;
  employee?: {
    employee_id: string;
    staff_id: string;
    firstname: string;
    lastname: string;
    full_name: string;
  };
  basic_salary: string;
  total_allowances: string;
  gross_salary: string;
  total_deductions: string;
  taxable_income: string;
  tax_amount: string;
  ssnit_employee: string;
  ssnit_employer: string;
  tier2_employee: string;
  tier2_employer: string;
  provident_fund_employee: string;
  provident_fund_employer: string;
  total_statutory: string;
  loan_deductions: string;
  attendance_deductions?: string;
  net_salary: string;
  payment_method: 'bank_transfer' | 'cash' | 'cheque';
  bank_account_number: string | null;
  bank_name: string | null;
  bank_branch: string | null;
  lines?: PayrollEntryLine[];
  pension_breakdown?: PensionBreakdownItem[];
  created_at: string;
}

export type PayrollRunStatus = 'draft' | 'processing' | 'review' | 'approved' | 'paid' | 'reversed' | 'failed' | 'cancelled';

export interface PayrollRun {
  id: string;
  payroll_period_id: string;
  period?: PayrollPeriod;
  run_type: 'regular' | 'supplementary' | 'reversal';
  status: PayrollRunStatus;
  total_gross: string;
  total_deductions: string;
  total_net: string;
  total_employer_cost: string;
  employee_count: number;
  run_by: string;
  runner?: { id: string; name: string };
  reviewed_by: string | null;
  reviewer?: { id: string; name: string } | null;
  reviewed_at: string | null;
  approved_by: string | null;
  approver?: { id: string; name: string } | null;
  approved_at: string | null;
  notes: string | null;
  entries_count?: number;
  entries?: PayrollEntry[];
  created_at: string;
  updated_at: string;
}

export interface CreatePayrollPeriodPayload {
  name: string;
  year: number;
  month: number;
  start_date: string;
  end_date: string;
}

export interface CreatePayrollRunPayload {
  payroll_period_id: string;
  run_type?: 'regular' | 'supplementary' | 'reversal';
  notes?: string;
}

export interface ProcessPayrollRunPayload {
  id: string;
  employee_ids?: string[];
  branch_id?: string;
}

export interface ReviewPayrollRunPayload {
  id: string;
  notes?: string;
}

export interface ApprovePayrollRunPayload {
  id: string;
  notes?: string;
}

export interface ReversePayrollRunPayload {
  id: string;
  reason?: string;
}

export interface CancelPayrollRunPayload {
  id: string;
  reason?: string;
}

export interface DeletePayrollPeriodPayload {
  message: string;
  id?: string;
}
