import { logger } from "../../common/logger.js";
import { printDiagnosticsToConsole, printTableToConsoleAndExitGracefully, textOrJson, } from "../../common/output.js";
import settings from "../../common/settings.js";
export async function create(argv) {
    const { account } = argv;
    const createResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/tunnels`, {
        method: "POST",
        headers: {
            Authorization: `Bearer ${argv.authToken}`,
            "Content-Type": "application/json",
        },
        body: JSON.stringify({ name: argv["tunnel-name"] }),
    });
    if (createResponse.ok) {
        const tunnel = await createResponse.json();
        await printTableToConsoleAndExitGracefully(tunnel);
    }
    else {
        logger.error({
            status: createResponse.status,
            statusText: createResponse.statusText,
            response: textOrJson(await createResponse.text()),
        }, "Failed to create tunnel for account");
        printDiagnosticsToConsole("Error: Failed to create tunnel for your account. Check the arguments.");
    }
}
//# sourceMappingURL=handler.js.map