"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Pools = void 0;
const ApiHandler_1 = require("../helper/ApiHandler");
const defi_providers_json_1 = __importDefault(require("../static/defi_providers.json"));
const chain_IDs_json_1 = __importDefault(require("../static/chain_IDs.json"));
class Pools {
    constructor() {
        var _a;
        this.apiHandler = new ApiHandler_1.ApiHandler('https://zap.dzap.io/v1');
        const parsedProviders = defi_providers_json_1.default;
        this.providers = (_a = parsedProviders.defiProviders) !== null && _a !== void 0 ? _a : {};
        this.validProviderIds = new Set(Object.keys(this.providers));
        this.chainIdMap = chain_IDs_json_1.default;
        this.validChainIds = new Set(Object.values(this.chainIdMap));
    }
    assertValidProvider(providerId) {
        if (!this.validProviderIds.has(providerId)) {
            const sample = Array.from(this.validProviderIds).slice(0, 10).join(", ");
            throw new Error(`Invalid provider "${providerId}". Must be one of: ${sample}${this.validProviderIds.size > 10 ? ", ..." : ""}`);
        }
    }
    assertValidChainId(chainId) {
        if (!Number.isInteger(chainId)) {
            throw new Error(`Invalid chain "${chainId}". Chain ID must be an integer.`);
        }
        if (!this.validChainIds.has(chainId)) {
            const sample = Array.from(this.validChainIds).slice(0, 10).join(", ");
            throw new Error(`Invalid chain ID "${chainId}". Must be one of: ${sample}${this.validChainIds.size > 10 ? ", ..." : ""}`);
        }
    }
    validProviderIDList() {
        return Array.from(this.validProviderIds);
    }
    async getPools(providerId, chainId) {
        this.assertValidProvider(providerId);
        this.assertValidChainId(chainId);
        const qs = new URLSearchParams({
            provider: providerId,
            chainId: String(chainId),
        });
        const endpoint = `/pools?${qs.toString()}`;
        return this.apiHandler.get(endpoint, {}, {});
    }
}
exports.Pools = Pools;
