/**
 * Reports router — profitability-reports + revenue-forecasting (wave-8 leaf 7)
 *                  + reports-analytics (wave-10 leaf 8)
 *                  + ar-aging-report (wave-12)
 *                  + financial-statements (wave-13).
 *
 * Mounted at /api/reports in the main route index.
 *
 * Sub-routes:
 *   /profitability              — tenant-wide profitability
 *   /profitability/projects/:id — single project
 *   /profitability/customers/:id — single customer
 *   /profitability/clients/:id  — single client
 *   /forecast                   — 6-month revenue forecast / legacy alias
 *   /revenue-forecast           — spec 116 revenue forecast
 *   /revenue                    — revenue ledger (wave B)
 *   /revenue/xlsx               — revenue ledger Excel (wave B)
 *   /revenue/trends             — revenue by period (wave-10)
 *   /invoices                   — invoice report (wave B)
 *   /invoices/xlsx              — invoice report Excel (wave B)
 *   /payments                   — payment report (wave B)
 *   /payments/xlsx              — payment report Excel (wave B)
 *   /expenses                   — expenses by category (wave-10)
 *   /customers                  — top customers ranking (wave-10)
 *   /productivity               — team productivity (wave-10)
 *   /overdue                    — overdue invoices (wave-10)
 *   /ar-aging                   — AR aging report (wave-12)
 *   /ar-aging/export.csv        — CSV export (Business+ only)
 *   /ar-aging/export.pdf        — PDF/HTML export (Business+ only)
 *   /ar-aging/statements        — bulk statement send (wave-12)
 *   /pl                         — P&L report JSON (wave-13)
 *   /pl/xlsx                    — P&L Excel export (wave-13)
 *   /cashflow                   — Cash Flow report JSON (wave-13)
 *   /cashflow/xlsx              — Cash Flow Excel export (wave-13)
 *   /uniform-format             — ITA uniform-structure export (מבנה אחיד, wave-13)
 *   /uniform-format/:id/download — signed download URL (24h TTL)
 */
import { Hono } from 'hono'
import type { AppEnv } from '../../types'
import { profitabilityRoutes } from './profitability'
import { forecastRoutes } from './forecast'
import { analyticsRoutes } from './analytics'
import { arAgingRoutes } from './ar-aging'
import { arAgingExportRoutes } from './ar-aging-export'
import { arAgingStatementsRoutes } from './ar-aging-statements'
import { badDebtReportRoute } from './bad-debt'
import { plReportRoutes } from './pl'
import { cashflowReportRoutes } from './cashflow'
import { uniformFormatRoutes } from './uniform-format'
import { reportsHubRoutes } from './hub'
import { inventoryReportRoutes } from './inventory'
// wave-14: israeli-tax-reports
import { taxReportRoutes } from '../reports-tax'
// wave-15: bituach-leumi
import { bituachLeumiRoutes } from './bituach-leumi'
// wave-15: accountant-export
import { accountantExportRoutes } from './accountant-exports'
// wave B: reports-analytics financial reports (revenue ledger, invoice, payment)
import { financialReportRoutes } from './financial-reports'
import { withholdingReportRoutes } from './withholding'

const reportsRouter = new Hono<AppEnv>()

reportsRouter.route('/profitability', profitabilityRoutes)
reportsRouter.route('/forecast', forecastRoutes)
reportsRouter.route('/revenue-forecast', forecastRoutes)

// wave B: revenue ledger + invoice/payment reports — /xlsx BEFORE bare paths
reportsRouter.route('/', financialReportRoutes)

// wave-10 leaf 8: reports-analytics (revenue trends at /revenue/trends)
reportsRouter.route('/', analyticsRoutes)
reportsRouter.route('/', withholdingReportRoutes)

// wave-12: ar-aging-report
reportsRouter.route('/ar-aging', arAgingRoutes)
reportsRouter.route('/ar-aging', arAgingExportRoutes)
reportsRouter.route('/ar-aging', arAgingStatementsRoutes)

// wave-12: bad-debt-writeoff
// /bad-debt/xlsx BEFORE /bad-debt to avoid capture
reportsRouter.route('/bad-debt', badDebtReportRoute)

// wave-13: financial-statements
// /pl/xlsx and /cashflow/xlsx routes are declared first within each sub-router
reportsRouter.route('/pl', plReportRoutes)
reportsRouter.route('/cashflow', cashflowReportRoutes)
reportsRouter.route('/inventory', inventoryReportRoutes)

// wave-13: uniform-format-export (מבנה אחיד)
reportsRouter.route('/uniform-format', uniformFormatRoutes)

// wave-14: israeli-tax-reports
// /vat/csv and /annual-summary/xlsx BEFORE /vat and /annual-summary to avoid sub-path capture
reportsRouter.route('/', taxReportRoutes)

// wave-15: bituach-leumi
// /bituach-leumi/xlsx BEFORE /bituach-leumi to avoid sub-path capture
reportsRouter.route('/', bituachLeumiRoutes)

// wave-15: accountant-export
// /accountant/exports/:id BEFORE /accountant/exports (specificity preserved within sub-router)
reportsRouter.route('/accountant', accountantExportRoutes)

// wave-13: reports-navigation-hub — /summary and /shortcuts MUST come last (broadest match)
reportsRouter.route('/', reportsHubRoutes)

export { reportsRouter }
