import { ENetworks } from './types';
const defaultRegtestConf = {
    'Application Options': {
        debuglevel: 'info',
        'no-macaroons': false,
        nolisten: true
    },
    Routing: {
        'routing.assumechanvalid': true
    },
    Bitcoin: {
        'bitcoin.active': true,
        'bitcoin.regtest': true,
        'bitcoin.node': 'bitcoind'
    },
    watchtower: {
        'watchtower.active': false
    },
    Bitcoind: {
        'bitcoind.rpchost': '127.0.0.1',
        'bitcoind.rpcuser': 'polaruser',
        'bitcoind.rpcpass': 'polarpass',
        'bitcoind.zmqpubrawblock': 'tcp://127.0.0.1:28334',
        'bitcoind.zmqpubrawtx': 'tcp://127.0.0.1:29335'
    }
};
const defaultTestnetBitcoindConf = {
    'Application Options': {
        debuglevel: 'info',
        'no-macaroons': false,
        maxbackoff: '2s',
        nolisten: true
    },
    Routing: {
        'routing.assumechanvalid': true
    },
    Bitcoin: {
        'bitcoin.active': true,
        'bitcoin.testnet': true,
        'bitcoin.node': 'neutrino'
    },
    Neutrino: {
        'neutrino.connect': '159.203.125.125:18333',
        'neutrino.addpeer': [
            'lnd.bitrefill.com:18333',
            'faucet.lightning.community',
            'testnet1-btcd.zaphq.io',
            'testnet2-btcd.zaphq.io',
            'testnet3-btcd.zaphq.io',
            'testnet4-btcd.zaphq.io'
        ],
        'neutrino.feeurl': 'https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json'
    }
};
class LndConf {
    constructor(network, customFields = {}) {
        this.network = network;
        this.customFields = customFields;
    }
    mergeConf(conf1, conf2) {
        const mergedConf = {};
        Object.keys(conf1).forEach((heading) => {
            const section = conf1[heading];
            let customSectionFields = {};
            if (conf2[heading]) {
                customSectionFields = conf2[heading];
            }
            mergedConf[heading] = Object.assign(Object.assign({}, section), customSectionFields);
        });
        Object.keys(conf2).forEach((heading) => {
            if (!mergedConf[heading]) {
                mergedConf[heading] = conf2[heading];
            }
        });
        return mergedConf;
    }
    getDefaultConf() {
        let defaultConfObj;
        switch (this.network) {
            case ENetworks.regtest: {
                defaultConfObj = defaultRegtestConf;
                break;
            }
            case ENetworks.testnet: {
                defaultConfObj = defaultTestnetBitcoindConf;
                break;
            }
            case ENetworks.mainnet: {
                throw new Error('Not implemented yet: Networks.mainnet case');
            }
        }
        return defaultConfObj;
    }
    build() {
        const defaultConfObj = this.getDefaultConf();
        const mergedConf = this.mergeConf(defaultConfObj, this.customFields);
        let confContent = '';
        Object.keys(mergedConf).forEach((heading) => {
            confContent += `[${heading}]\n`;
            const section = mergedConf[heading];
            Object.keys(section).forEach((key) => {
                const value = section[key];
                if (Array.isArray(value)) {
                    value.forEach((valueItem) => {
                        confContent += `${key}=${valueItem}\n`;
                    });
                }
                else {
                    confContent += `${key}=${String(value)}\n`;
                }
            });
            confContent += '\n';
        });
        return confContent;
    }
}
export default LndConf;
//# sourceMappingURL=lnd.conf.js.map