import { createApiClient } from "../../common/api/client.js";
import { printJsonToConsoleAndExitGracefully, printResultToConsole, } from "../../common/output.js";
export async function list(argv) {
    const { account } = argv;
    const client = createApiClient({ authToken: argv.authToken });
    const response = await client.get(`/v1/accounts/${account}/client-mtls-ca-certificates`, {
        operation: "Failed to list CA certificates",
        errorMessage: "Error: Failed to list CA certificates.",
    });
    if (argv.output === "json") {
        await printJsonToConsoleAndExitGracefully(response);
        return;
    }
    if (response.data.length === 0) {
        printResultToConsole("No CA certificates found");
        return;
    }
    printResultToConsole(`Found ${response.data.length} CA certificate(s):\n`);
    for (const cert of response.data) {
        const subject = cert.certificateInfo.subject.replace(/\n/g, ", ");
        printResultToConsole(`  ID: ${cert.id}\n` +
            `  Name: ${cert.name}\n` +
            `  Subject: ${subject}\n` +
            `  Valid from: ${cert.certificateInfo.validFrom}\n` +
            `  Valid to: ${cert.certificateInfo.validTo}\n`);
    }
}
//# sourceMappingURL=handler.js.map