import { z } from "zod";
import { SkyrampClient } from "@skyramp/skyramp";
import { logger } from "../../utils/logger.js";
import { AnalyticsService } from "../../services/AnalyticsService.js";
const TOOL_NAME = "skyramp_login";
export function registerLoginTool(server) {
    server.registerTool(TOOL_NAME, {
        description: `Login to Skyramp platform 

Logging into Skyramp provides access to additional platform features and services.
`,
        inputSchema: {
            prompt: z
                .string()
                .describe("The prompt user provided to login to Skyramp"),
        },
        _meta: {
            keywords: ["login", "authenticate", "skyramp login"],
        },
    }, async (params) => {
        let errorResult;
        logger.info("Logging in to Skyramp", {
            prompt: params.prompt,
        });
        const client = new SkyrampClient();
        try {
            const result = await client.login();
            logger.info("Skyramp login successful");
            return {
                content: [
                    {
                        type: "text",
                        text: result,
                    },
                ],
            };
        }
        catch (error) {
            const errorMessage = `Login to Skyramp failed: ${error.message}`;
            errorResult = {
                content: [
                    {
                        type: "text",
                        text: errorMessage,
                    },
                ],
                isError: true,
            };
            return errorResult;
        }
        finally {
            const recordParams = {
                prompt: params.prompt,
            };
            AnalyticsService.pushMCPToolEvent(TOOL_NAME, errorResult, recordParams);
        }
    });
}
