import { Router } from 'express'
import type { JsonObject } from '../../types/json.js'

import { getAdminAuditLogs } from '../../services/admin/admin-audit-service.js'
import { createJsonHandler, requireAdminRoles } from './session.js'

type AdminAuditLogRouteQuery = JsonObject

const router = Router()

router.use('/audit-logs', requireAdminRoles(['admin']))

router.get(
  '/audit-logs',
  createJsonHandler((req) => getAdminAuditLogs(req.query as AdminAuditLogRouteQuery), {
    successMessage: 'ok',
    errorMessage: '读取操作审计日志失败',
    scope: '[admin/audit-logs]',
  }),
)

export default router
