"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchQuote = fetchQuote;
exports.fetchRoutePlan = fetchRoutePlan;
exports.fetchExecutionPlan = fetchExecutionPlan;
exports.fetchProviderCapabilities = fetchProviderCapabilities;
const axios_1 = __importDefault(require("axios"));
const config_1 = require("../config");
async function fetchQuote(params) {
    const base = (0, config_1.tokenAggUrl)();
    const q = new URLSearchParams({
        chainId: String(params.chainId),
        tokenIn: params.tokenIn,
        tokenOut: params.tokenOut,
        amountIn: params.amountIn,
    });
    const { data } = await axios_1.default.get(`${base}/api/v1/quote?${q}`, { timeout: 60000 });
    return data;
}
async function fetchRoutePlan(body) {
    const { data } = await axios_1.default.post(`${(0, config_1.tokenAggUrl)()}/api/v2/routes/plan`, {
        sourceChainId: body.sourceChainId,
        destinationChainId: body.destinationChainId,
        tokenIn: body.tokenIn,
        tokenOut: body.tokenOut,
        amountIn: body.amountIn,
        recipient: body.recipient,
        constraints: { maxSlippageBps: body.maxSlippageBps ?? 50, allowBridge: false },
    }, { timeout: 120000 });
    return data;
}
async function fetchExecutionPlan(body) {
    const { data } = await axios_1.default.post(`${(0, config_1.tokenAggUrl)()}/api/v2/routes/internal-execution-plan`, {
        sourceChainId: body.sourceChainId,
        destinationChainId: body.destinationChainId,
        tokenIn: body.tokenIn,
        tokenOut: body.tokenOut,
        amountIn: body.amountIn,
        recipient: body.recipient,
        constraints: { maxSlippageBps: body.maxSlippageBps ?? 50, allowBridge: false },
    }, { timeout: 120000 });
    return data;
}
async function fetchProviderCapabilities(chainId) {
    const { data } = await axios_1.default.get(`${(0, config_1.tokenAggUrl)()}/api/v2/providers/capabilities?chainId=${chainId}`, {
        timeout: 30000,
    });
    return data;
}
