/**
 * tax-reports.ts — DTO types for Israeli tax compliance reports.
 * Spec: 2026-06-01-israeli-tax-reports (wave-14)
 */

// ── PCN874 VAT Report ─────────────────────────────────────────────────────────

export interface Pcn874Report {
  /** Period start date (YYYY-MM-DD) */
  periodFrom: string
  /** Period end date (YYYY-MM-DD) */
  periodTo: string
  /** Tenant VAT filing period (monthly | bimonthly) */
  vatPeriod: 'monthly' | 'bimonthly'

  // Output VAT (Sales)
  /** Number of tax invoices issued */
  outputInvoiceCount: number
  /** Gross turnover from tax invoices (ILS) */
  outputTurnoverIls: string
  /** Output VAT on tax invoices (ILS) */
  outputVatIls: string
  /** Number of credit notes issued */
  creditNoteCount: number
  /** Total credit note amounts (ILS, positive) */
  creditNoteTurnoverIls: string
  /** VAT reversed by credit notes (ILS, positive) */
  creditNoteVatIls: string
  /** Net output VAT = outputVatIls − creditNoteVatIls (ILS) */
  netOutputVatIls: string

  // Input VAT (Purchases)
  /** Number of approved deductible expense records */
  inputExpenseCount: number
  /** Total deductible expense amounts (ILS) */
  inputExpenseTotalIls: string
  /** Input VAT on deductible expenses (ILS) */
  inputVatIls: string
  /** Net input VAT (ILS) */
  netInputVatIls: string

  // Summary
  /** VAT payable to ITA = netOutputVatIls − netInputVatIls (ILS) */
  vatPayableIls: string
}

// ── Annual Income Summary ─────────────────────────────────────────────────────

export interface AnnualExpenseBreakdownRow {
  category: string
  totalIls: string
  deductibleIls: string
}

export interface AnnualSummaryInvoiceRow {
  number: string
  date: string
  customer: string
  subtotalIls: string
  vatIls: string
  totalIls: string
}

export interface AnnualSummaryMileageRow {
  date: string
  description: string
  distanceKm: string
  reimbursementIls: string
}

export interface AnnualSummaryPayoutRow {
  contractor: string
  datePaid: string
  netAmountIls: string
}

export interface AnnualSummaryDetail {
  invoices: AnnualSummaryInvoiceRow[]
  mileage: AnnualSummaryMileageRow[]
  payouts: AnnualSummaryPayoutRow[]
}

export interface AnnualIncomeSummary {
  year: number

  // Income
  /** Total invoiced income (sum of subtotals, excl. VAT) (ILS) */
  totalInvoicedIncomeIls: string
  /** Bad debt write-offs (status BAD_DEBT / WRITTEN_OFF) (ILS) */
  badDebtWriteOffIls: string
  /** Adjusted income = totalInvoicedIncomeIls − badDebtWriteOffIls (ILS) */
  adjustedIncomeIls: string

  // Deductions
  /** Deductible expenses by category */
  expenseBreakdown: AnnualExpenseBreakdownRow[]
  /** Mileage reimbursement deduction for the year (ILS) */
  mileageDeductionIls: string
  /** PAID contractor payout bills net amount for the year (ILS) */
  contractorPayoutsIls: string
  /** Total deductible expenses (ILS) */
  totalDeductionsIls: string

  // Net
  /** Net taxable income = adjustedIncomeIls − totalDeductionsIls (ILS) */
  netTaxableIncomeIls: string
}

// ── Advance Tax Estimate ──────────────────────────────────────────────────────

export interface TaxBracket {
  bracketType: string
  rate: string
  thresholdIls: string | null
}

export interface AdvanceTaxEstimate {
  year: number

  // YTD performance
  /** Year-to-date net income (ILS) */
  ytdNetIncomeIls: string
  /** Months elapsed so far in the year */
  monthsElapsed: number
  /** ITA-assigned advance rate (percentage, e.g. 15.00); null = not configured */
  advanceTaxRatePct: string | null

  // Estimated annual figures
  /** Projected annual net income (ILS) */
  estimatedAnnualIncomeIls: string
  /** Brackets used for calculation */
  taxBrackets: TaxBracket[]
  /** Estimated annual income tax (ILS, marginal banding) */
  estimatedAnnualIncomeTaxIls: string

  // Advance tracking
  /** Advance payments made YTD (ILS); from tenant_settings.advance_payments_ytd_ils */
  advancePaymentsYtdIls: string
  /** Recommended advance per remaining month (ILS) */
  recommendedAdvancePerRemainingMonthIls: string
}

// ── Tax Settings ──────────────────────────────────────────────────────────────

export interface TaxSettings {
  vatPeriod: 'monthly' | 'bimonthly'
  advanceTaxRatePct: string | null
  /** Manually-entered YTD advance payments already filed (ILS) */
  advancePaymentsYtdIls: string | null
}
