import * as dotenv from 'dotenv';
import * as path from 'path';

dotenv.config({ path: path.resolve(__dirname, '../../../.env') });
dotenv.config();

const repoRoot = process.env.PROXMOX_ROOT || path.resolve(__dirname, '../../../../..');

function mainnetRpc(): string {
  return (
    process.env.MAINNET_RPC_URL ||
    process.env.ETHEREUM_MAINNET_RPC ||
    'https://ethereum-rpc.publicnode.com'
  );
}

export const checkpointIndexerConfig = {
  port: parseInt(process.env.CHECKPOINT_INDEXER_PORT || '3099', 10),
  mainnetRpc: mainnetRpc(),
  chain138Rpc: process.env.CHAIN138_RPC_URL || 'http://192.168.11.211:8545',
  checkpointProxy: process.env.CHAIN138_MAINNET_CHECKPOINT_PROXY || '',
  legacyMirror: process.env.TRANSACTION_MIRROR_MAINNET || '0x4CF42c4F1dBa748601b8938be3E7ABD732E87cE9',
  legacyTether: process.env.MAINNET_TETHER_ADDRESS || '0x15DF1D5BFDD8Aa4b380445D4e3E9B38d34283619',
  batchPayloadDir:
    process.env.CHECKPOINT_BATCH_PAYLOAD_DIR ||
    path.join(repoRoot, 'reports/checkpoint-indexer/batches'),
  blockscoutApi:
    process.env.CHECKPOINT_BLOCKSCOUT_API || 'https://explorer.d-bis.org/api/v2',
  enrichTokenTransfers: process.env.CHECKPOINT_ENRICH_TOKEN_TRANSFERS !== '0',
  usdEnrichEnabled: process.env.CHECKPOINT_USD_ENRICH !== '0',
  tokenAggregationApiUrl:
    process.env.CHECKPOINT_TOKEN_AGGREGATION_URL ||
    process.env.TOKEN_AGGREGATION_API_URL ||
    'https://explorer.d-bis.org/api/v1',
  usdRequestDelayMs: parseInt(process.env.CHECKPOINT_USD_REQUEST_DELAY_MS || '80', 10),
  addressActivityRegistry: process.env.ADDRESS_ACTIVITY_REGISTRY_MAINNET || '',
  addressActivityRegistryV2: process.env.ADDRESS_ACTIVITY_REGISTRY_V2_MAINNET || '',
  iso20022IntakeGateway: process.env.ISO20022_INTAKE_GATEWAY_MAINNET || '',
  participantSurface: process.env.CHAIN138_PARTICIPANT_SURFACE_MAINNET || '',
} as const;
