/**
 * Portal dashboard route — tenant-portals (wave 9d, Task 6).
 * GET /api/portal/dashboard
 */
import { Hono } from 'hono'
import { getPortalDashboard } from '@zync/db/queries'
import type { AppEnv } from '../../types'
import { portalAuthMiddleware, type PortalAuthVariables } from '../../middleware/portalAuth'

type PortalDataEnv = {
  Bindings: AppEnv['Bindings']
  Variables: PortalAuthVariables
}

export const portalDashboardRoutes = new Hono<PortalDataEnv>()

portalDashboardRoutes.use('*', portalAuthMiddleware)

portalDashboardRoutes.get('/', async (c) => {
  const portal = c.get('portal')
  const db = c.get('db')
  const dashboard = await getPortalDashboard(db, portal.tenantId, portal.customerId)
  return c.json(dashboard, 200)
})
