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