/**
 * @djangocfg/api - Shared API Package
 *
 * Core authentication API (cfg_accounts only).
 * Extensions are now in separate packages:
 * - @djangocfg/ext-support
 * - @djangocfg/ext-payments
 * - etc.
 */

// ============================================================================
// Main API from cfg_accounts (authentication)
// ============================================================================
export * from './generated/cfg_accounts';
export { API, LocalStorageAdapter, MemoryStorageAdapter } from './generated/cfg_accounts';
export { Schemas, Fetchers, Enums } from './generated/cfg_accounts';

// ============================================================================
// CFG Accounts Type Namespace
// ============================================================================
export * as CfgAccountsTypes from './generated/cfg_accounts';

// ============================================================================
// Centrifugo Fetchers (for WebSocket token refresh)
// ============================================================================
export { getCentrifugoAuthTokenRetrieve } from './generated/cfg_centrifugo';

// ============================================================================
// WebPush API (for push notifications)
// ============================================================================
export { API as WebPushAPI } from './generated/cfg_webpush';
export * as WebPushTypes from './generated/cfg_webpush';

/**
 * Base Client for all API services
 *
 * Provides:
 * - Centralized API instance with JWT token management
 * - LocalStorage adapter for browser environments
 * - Singleton pattern for API client
 */

import { API, LocalStorageAdapter } from './generated/cfg_accounts';

/**
 * Singleton API instance with JWT token management
 * Uses LocalStorage for token persistence
 */
const isStaticBuild = process.env.NEXT_PUBLIC_STATIC_BUILD === 'true';
const apiUrl = isStaticBuild ? '' : process.env.NEXT_PUBLIC_API_URL || '';

const api = new API(
  apiUrl,
  {
    storage: new LocalStorageAdapter()
  }
);

/**
 * Base Client Class
 *
 * Service classes can extend this to access api instance
 */
export class BaseClient {
  protected static api = api;
}

/**
 * Export API instance for direct access
 */
export { api };
