import { registerAs } from '@nestjs/config';

export interface BlockchainConfig {
  rpcUrl: string;
  chainId: number;
  networkId: number;
  contracts: {
    licenseNft: string | undefined;
    approvalManager: string | undefined;
    departmentRegistry: string | undefined;
    workflowRegistry: string | undefined;
  };
  platformWallet: {
    privateKey: string | undefined;
  };
  gasLimit: number;
  confirmationBlocks: number;
}

export default registerAs('blockchain', () => ({
  rpcUrl: process.env.BESU_RPC_URL || 'http://localhost:8545',
  chainId: parseInt(process.env.BESU_CHAIN_ID || '1337', 10),
  networkId: parseInt(process.env.BESU_NETWORK_ID || '2024', 10),
  contracts: {
    licenseNft: process.env.CONTRACT_ADDRESS_LICENSE_NFT,
    approvalManager: process.env.CONTRACT_ADDRESS_APPROVAL_MANAGER,
    departmentRegistry: process.env.CONTRACT_ADDRESS_DEPARTMENT_REGISTRY,
    workflowRegistry: process.env.CONTRACT_ADDRESS_WORKFLOW_REGISTRY,
  },
  platformWallet: {
    privateKey: process.env.PLATFORM_WALLET_PRIVATE_KEY,
  },
  gasLimit: parseInt(process.env.BLOCKCHAIN_GAS_LIMIT || '8000000', 10),
  confirmationBlocks: parseInt(process.env.BLOCKCHAIN_CONFIRMATION_BLOCKS || '1', 10),
}));
