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

import { getAdminDashboardSummary } from '../../services/admin/admin-dashboard-service.js'
import { getAdminLoginLogs } from '../../services/admin/admin-login-log-service.js'
import { createJsonHandler, requireAdminRoles } from './session.js'

const router = Router()

router.use('/dashboard', requireAdminRoles(['admin', 'operator', 'support']))

router.get(
  '/dashboard/summary',
  createJsonHandler(() => getAdminDashboardSummary(), {
    successMessage: 'ok',
    errorMessage: '读取后台概览失败',
    scope: '[admin/dashboard/summary]',
  }),
)

router.get(
  '/dashboard/login-logs',
  createJsonHandler((req) => getAdminLoginLogs(req.query as JsonObject), {
    successMessage: 'ok',
    errorMessage: '读取登录记录失败',
    scope: '[admin/dashboard/login-logs]',
  }),
)

export default router
