/**
 * Configuration for Tatum SDK integration with ChainID 138
 */

// Load environment variables
import * as dotenv from 'dotenv';
dotenv.config();

export const CHAIN_ID = 138;
export const CHAIN_ID_HEX = '0x8a'; // 138 in hex
export const CHAIN_NAME = 'DeFi Oracle Meta Mainnet';

/**
 * Default RPC endpoints
 * Update these to point to your deployed RPC nodes
 */
export const DEFAULT_RPC_URL = process.env.RPC_URL || 'http://localhost:8545';
export const DEFAULT_WS_URL = process.env.WS_URL || 'ws://localhost:8546';

/**
 * Network configuration for ChainID 138
 */
export const NETWORK_CONFIG = {
  chainId: CHAIN_ID,
  chainIdHex: CHAIN_ID_HEX,
  name: CHAIN_NAME,
  nativeCurrency: {
    name: 'Ether',
    symbol: 'ETH',
    decimals: 18,
  },
  rpcUrls: {
    default: {
      http: [DEFAULT_RPC_URL],
      webSocket: [DEFAULT_WS_URL],
    },
  },
  blockExplorers: {
    default: {
      name: 'Blockscout',
      url: process.env.EXPLORER_URL || 'https://explorer.d-bis.org',
    },
  },
};

/**
 * Tatum SDK configuration
 */
export interface TatumConfig {
  rpcUrl?: string;
  wsUrl?: string;
  verbose?: boolean;
  apiKey?: string; // Optional: for Tatum cloud features (not used for custom RPC)
}

export const getTatumConfig = (config?: TatumConfig): TatumConfig => {
  return {
    rpcUrl: config?.rpcUrl || DEFAULT_RPC_URL,
    wsUrl: config?.wsUrl || DEFAULT_WS_URL,
    verbose: config?.verbose ?? true,
    apiKey: config?.apiKey,
  };
};

