/**
 * Customers route group — customers module.
 * Mounted at /api/customers in apps/zync-api/src/routes/index.ts (via manifest).
 *
 * All sub-routes run behind authMiddleware so the session + db handle are
 * populated. Permission checks are applied per-route via requirePermission().
 */
import { Hono } from 'hono'
import type { AppEnv } from '../../types'
import { authMiddleware } from '../../middleware/auth'
import { customersIndexRoute } from './index'
import { contactsRoute } from './contacts'
import { portalRoute } from './portal'
import { portalSessionsRoute } from './portalSessions'
import { communicationsRoute } from './communications'
import { customerDedupRoutes } from './dedup'
// wave-16: customer-statement (spec 183) — mounted BEFORE /:id index to avoid capture
import { customerStatementRoute } from './statement'

const customerRoutes = new Hono<AppEnv>()

// All customer routes require an authenticated session
customerRoutes.use('*', authMiddleware)

// Mount sub-routers
// customer statement BEFORE broad /:id index to avoid /:id capturing /statement sub-routes
customerRoutes.route('/', customerStatementRoute)
customerRoutes.route('/', customersIndexRoute)
customerRoutes.route('/', contactsRoute)
customerRoutes.route('/', portalRoute)
customerRoutes.route('/', portalSessionsRoute)
customerRoutes.route('/', communicationsRoute)
customerRoutes.route('/', customerDedupRoutes)

export { customerRoutes }
