/**
 * HTTP Client Module Test Setup
 *
 * This file provides setup and utilities for HTTP client module testing,
 * including mock configurations and test helpers.
 */

import { jest } from '@jest/globals'

// Mock credential manager for tests
jest.mock('@/core/credential-manager', () => ({
  CredentialManager: jest.fn(),
  SignerFactory: {
    createSigner: jest.fn()
  },
  PlatformDetector: {
    detectPlatform: jest.fn()
  }
}))

// Mock external dependencies
jest.mock('https-proxy-agent', () => ({
  HttpsProxyAgent: jest.fn()
}))

jest.mock('winston', () => ({
  createLogger: jest.fn(() => ({
    info: jest.fn(),
    error: jest.fn(),
    warn: jest.fn(),
    debug: jest.fn()
  })),
  format: {
    combine: jest.fn(),
    timestamp: jest.fn(),
    json: jest.fn()
  },
  transports: {
    Console: jest.fn(),
    File: jest.fn()
  }
}))

// Global test utilities
global.testUtils = {
  // Mock HTTP response
  mockHttpResponse: (data: any, status = 200) => ({
    status,
    statusText: status >= 200 && status < 300 ? 'OK' : 'Error',
    ok: status >= 200 && status < 300,
    data,
    headers: new Headers({ 'content-type': 'application/json' })
  }),

  // Mock platform request
  mockPlatformRequest: (platform: string, accountId: string) => ({
    platform,
    accountId,
    method: 'GET' as const,
    url: '/api/test',
    headers: {},
    options: {}
  }),

  // Mock authentication context
  mockAuthContext: (platform: string) => ({
    accountId: 'test-account',
    platform,
    authType: 'signature' as const,
    isValid: true,
    lastRefresh: new Date(),
    failureCount: 0
  })
}

// Extend global types for test utilities
declare global {
  var testUtils: {
    mockHttpResponse: (data: any, status?: number) => any
    mockPlatformRequest: (platform: string, accountId: string) => any
    mockAuthContext: (platform: string) => any
  }
}

export {}