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

const getMock = vi.fn()

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

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

  it('gets system settings', async () => {
    const mockSettings = {
      data: {
        system: {
          name: 'UserSystem',
          version: '1.0.0',
          environment: 'production',
          description: 'User management system',
        },
        security: {
          password_min_length: 8,
          password_require_uppercase: true,
          password_require_lowercase: true,
          password_require_numbers: true,
          password_require_symbols: true,
          password_history: 5,
          totp_enabled: true,
          login_fail_lock: true,
          login_fail_threshold: 5,
          login_fail_duration: 30,
          session_timeout: 3600,
          device_trust_duration: 2592000,
        },
        features: {
          email_verification: true,
          phone_verification: false,
          oauth_providers: ['google', 'github'],
          sso_enabled: false,
          operation_log_enabled: true,
          login_log_enabled: true,
          data_export_enabled: true,
          data_import_enabled: true,
        },
      },
    }

    getMock.mockResolvedValue(mockSettings)

    const { getSettings } = await import('./settings')
    const result = await getSettings()

    expect(getMock).toHaveBeenCalledWith('/admin/settings')
    expect(result).toEqual(mockSettings.data)
  })
})
