import { apiGet } from '@/lib/http'
import type { AdminDashboardSummary, AdminLoginLogListResult } from '@/types/admin'

export function fetchAdminDashboardSummary() {
  return apiGet<AdminDashboardSummary>('/api/v1/admin/dashboard/summary')
}

export function fetchAdminLoginLogs(
  params: {
    page?: number
    pageSize?: number
    username?: string
    dateFrom?: string
    dateTo?: string
  } = {},
) {
  const search = new URLSearchParams()
  if (params.page) search.set('page', String(params.page))
  if (params.pageSize) search.set('pageSize', String(params.pageSize))
  if (params.username) search.set('username', params.username)
  if (params.dateFrom) search.set('dateFrom', params.dateFrom)
  if (params.dateTo) search.set('dateTo', params.dateTo)
  const queryString = search.toString()
  return apiGet<AdminLoginLogListResult>(
    `/api/v1/admin/dashboard/login-logs${queryString ? `?${queryString}` : ''}`,
  )
}
