/**
 * Integration test for Pacifica account balance query
 *
 * This test validates the complete flow of querying account balances from Pacifica
 * including authentication, request processing, and response handling.
 * Tests MUST FAIL until implementation is complete.
 */

import { describe, test, expect, beforeEach, jest } from '@jest/globals'

// Import types that will be implemented
import type { IUniversalHttpClient, HttpClientRequest, HttpClientResponse } from '@/types/httpClientCore'

describe('Pacifica Balance Query Integration', () => {
  let httpClient: IUniversalHttpClient

  beforeEach(async () => {
    // This will fail until IUniversalHttpClient is implemented
    // eslint-disable-next-line @typescript-eslint/no-require-imports
    const { HttpClientCore } = require('@/core/http-client/HttpClientCore')
    httpClient = new HttpClientCore()

    // Register Pacifica adapter
    // eslint-disable-next-line @typescript-eslint/no-require-imports
    const { PacificaHttpAdapter } = require('@/adapters/pacifica/PacificaHttpAdapter')
    const pacificaAdapter = new PacificaHttpAdapter({
      platform: 'pacifica',
      baseUrl: 'https://api.pacifica.fi',
      authConfig: { type: 'signature', algorithm: 'Ed25519' }
    })
    httpClient.registerPlatform('pacifica', pacificaAdapter)
  })

  test('should query account balances successfully', async () => {
    const request: HttpClientRequest = {
      platform: 'pacifica',
      accountId: 'integration-test-account',
      method: 'GET',
      url: '/api/v1/account/balances'
    }

    const response: HttpClientResponse = await httpClient.request(request)

    expect(response).toBeDefined()
    expect(response.ok).toBe(true)
    expect(response.data).toBeDefined()
    expect(response.data.balances).toBeDefined()
    expect(Array.isArray(response.data.balances)).toBe(true)
    expect(response.metadata.platform).toBe('pacifica')
    expect(response.metadata.authenticated).toBe(true)
  })

  test('should handle authentication with credential-manager', async () => {
    const request: HttpClientRequest = {
      platform: 'pacifica',
      accountId: 'credential-test-account',
      method: 'GET',
      url: '/api/v1/account/info'
    }

    const response: HttpClientResponse = await httpClient.request(request)

    expect(response).toBeDefined()
    expect(response.metadata.authenticated).toBe(true)
    expect(response.metadata.signatureAlgorithm).toBe('Ed25519')
    expect(response.metadata.credentialManagerUsed).toBe(true)
  })
})