import { beforeEach, describe, expect, it, vi } from 'vitest'

const getMock = vi.fn()

vi.mock('@/lib/http/client', () => ({
  get: getMock,
}))

describe('stats service', () => {
  beforeEach(() => {
    getMock.mockReset()
  })

  it('gets dashboard stats', async () => {
    const mockStats = {
      total_users: 100,
      active_users: 75,
      new_users_today: 5,
      total_devices: 200,
      trusted_devices: 150,
    }

    getMock.mockResolvedValue(mockStats)

    const { getDashboardStats } = await import('./stats')
    const result = await getDashboardStats()

    expect(getMock).toHaveBeenCalledWith('/admin/stats/dashboard')
    expect(result).toEqual(mockStats)
  })

  it('gets user stats', async () => {
    const mockUserStats = {
      total: 100,
      active: 75,
      inactive: 25,
      verified: 80,
      unverified: 20,
    }

    getMock.mockResolvedValue(mockUserStats)

    const { getUserStats } = await import('./stats')
    const result = await getUserStats()

    expect(getMock).toHaveBeenCalledWith('/admin/stats/users')
    expect(result).toEqual(mockUserStats)
  })
})
