import { Router } from 'express'

import { getAdminOrderDetail, getAdminOrders } from '../../services/admin/admin-read-service.js'
import { createJsonHandler } from './shared.js'
import type {
  AdminOrderRouteParams,
  AdminOrderRouteQuery,
} from '../../types/admin-route-inputs.js'

const router = Router()

router.get('/orders', createJsonHandler(
  (req) => getAdminOrders(req.query as AdminOrderRouteQuery),
  {
    successMessage: 'ok',
    errorMessage: '读取订单列表失败',
    scope: '[admin/orders]',
  },
))

router.get('/orders/:orderId', createJsonHandler(
  (req) => getAdminOrderDetail((req.params as AdminOrderRouteParams).orderId),
  {
    successMessage: 'ok',
    errorMessage: '读取订单详情失败',
    scope: '[admin/orders/:orderId]',
  },
))

export default router
