/**
 * Bituach Leumi (NII) types — spec 175, wave-15.
 */

/**
 * NII rate configuration stored in KV as `nii_rates:{year}`.
 */
export interface NIIRates {
  /** Reduced rate (e.g. 0.0597) — applies up to band1_monthly_ils */
  reduced_rate: number
  /** Full rate (e.g. 0.1783) — applies from band1_monthly_ils to income_cap_monthly_ils */
  full_rate: number
  /** Monthly threshold for reduced rate band (e.g. 6331 — 60% of average wage) */
  band1_monthly_ils: number
  /** Monthly average wage (e.g. 10551) */
  avg_wage_monthly_ils: number
  /** Monthly income cap above which no NII is charged (e.g. 45075) */
  income_cap_monthly_ils: number
  /** Optional: fraction of total contribution that is health insurance (for display split) */
  health_share?: number
}

/**
 * Estimated NII contribution breakdown.
 */
export interface NIIEstimate {
  /** National insurance component (total minus health) */
  national_insurance: number
  /** Health insurance component */
  health_insurance: number
  /** Total NII contribution (national + health) */
  total: number
}

/**
 * Advance payment made for a specific month.
 */
export interface NiiAdvanceByMonth {
  month: number
  amount: number
}

/**
 * Full Bituach Leumi annual report response.
 */
export interface BituachLeumiReport {
  year: number
  /** Gross revenue excl. VAT (issued/paid invoices) */
  gross_revenue_net_vat: string
  /** Deductible expenses excl. VAT */
  deductible_expenses: string
  /** Contractor payouts (payout_bills PAID) */
  contractor_payouts: string
  /** Manual depreciation deduction entered by user */
  depreciation_deduction: string
  /** Net income = gross - expenses - payouts - depreciation */
  net_income: string
  /** Monthly average net income */
  monthly_average: string
  /** Estimated NII contributions */
  nii_contributions: NIIEstimate
  /** NII advance payments already paid */
  advances_paid: {
    total: number
    by_month: NiiAdvanceByMonth[]
  }
}

/**
 * DTO for a single NII advance payment record.
 */
export interface NiiAdvancePayment {
  id: string
  tenant_id: string
  user_id: string
  year: number
  month: number
  amount: number
  paid_at: string
  notes: string | null
  created_at: string
}

/**
 * Input for creating or updating an NII advance payment.
 */
export interface CreateNiiAdvanceInput {
  year: number
  month: number
  amount: number
  paid_at: string
  notes?: string
}
