"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZapCallDataGeneratorTool = void 0;
const zod_1 = require("zod");
const ai_1 = require("ai");
const zap_1 = require("../zap");
const zapRegistry_1 = require("./zapRegistry");
const zapCallDataGeneratorToolInputSchema = zod_1.z.object({
    srcToken: zod_1.z.string().describe("Source token contract address"),
    srcChainId: zod_1.z.number().describe("Chain ID of source chain"),
    srcDecimals: zod_1.z.number().describe("decimals of source chain"),
    destToken: zod_1.z.string().describe("Destination token contract address"),
    destChainId: zod_1.z.number().describe("Chain ID of destination chain"),
    destDecimals: zod_1.z.number().describe("decimals of destination chain"),
    account: zod_1.z.string().describe("The user's wallet address"),
    amount: zod_1.z.number().finite().nonnegative().describe("The original amount of source token to zap (not multiplied by decimals)"),
    decimalAmount: zod_1.z.number().finite().nonnegative().describe("The value of amount multiplied by srcDecimals, used for call data generation"),
    recipient: zod_1.z.string().describe("Wallet address that will receive the output tokens in most case same as the account"),
    sessionId: zod_1.z.string().describe("The current session ID for this user"),
    type: zod_1.z.enum(["swap", "bridge", "zap"]).describe("Type of operation: swap, bridge, or zap"),
});
class ZapCallDataGeneratorTool {
    constructor() {
        this.zap = new zap_1.Zap();
        this.tool = (0, ai_1.tool)({
            description: "Generate call data for zapping and store it in the zap registry.",
            inputSchema: zapCallDataGeneratorToolInputSchema,
            execute: async (parameters) => {
                console.log(`Generating zap route data for session ${parameters.sessionId}...`);
                const routeData = await this.zap.getRoute(parameters.srcToken, parameters.srcChainId, parameters.srcDecimals, parameters.destToken, parameters.destChainId, parameters.destDecimals, parameters.account, parameters.amount, parameters.recipient, parameters.type, parameters.sessionId);
                if (typeof routeData === "string" && routeData.startsWith("Unable to retrieve route")) {
                    console.log(`Error generating zap route data for session ${parameters.sessionId}: ${routeData}`);
                    return routeData; // Return the error message
                }
                const routePayload = Object.assign(Object.assign({}, routeData), { type: parameters.type });
                // Save routeData instead of returning it
                (0, zapRegistry_1.saveZapData)(parameters.sessionId, routePayload);
                console.log(`Zap route data stored for session ${parameters.sessionId}`);
                return { message: `Zap data stored for session ${parameters.sessionId}` };
            }
        });
    }
}
exports.ZapCallDataGeneratorTool = ZapCallDataGeneratorTool;
