import { captureEvent } from "../../common/analytics/lib.js";
import { authenticate } from "../../common/middleware/authentication.js";
import { confirmLinkedConfig } from "../../common/middleware/confirm-linked-config.js";
import { fetchAccount } from "../../common/middleware/get-account-param.js";
import { fetchProject } from "../../common/middleware/get-project-param.js";
import { configure } from "../../common/middleware/user-configuration.js";
import { identify } from "../../common/middleware/user-identification.js";
import { validateFileExists } from "../../common/validators/argument-validators.js";
import { create } from "../../mtls-certificates/create/handler.js";
export default {
    desc: "Creates a new mTLS certificate for a project",
    command: "create",
    builder: (yargs) => {
        return yargs
            .usage("$0 mtls-certificates create --name <name> --cert <file> --key <file> --environment <env> [options]")
            .option("name", {
            type: "string",
            describe: "The name of the certificate (alphanumeric with underscores)",
        })
            .option("cert", {
            type: "string",
            describe: "Path to the PEM-encoded certificate file",
            normalize: true,
        })
            .option("key", {
            type: "string",
            describe: "Path to the PEM-encoded private key file",
            normalize: true,
        })
            .option("environment-type", {
            type: "array",
            describe: "Environment types where the certificate should be enabled (can be repeated: --environment-type development --environment-type production)",
            choices: ["development", "preview", "production"],
        })
            .option("api-key", {
            type: "string",
            describe: "The API Key from Zuplo",
            envVar: "API_KEY",
            alias: "apikey",
        })
            .option("account", {
            type: "string",
            describe: "The account name",
        })
            .option("project", {
            type: "string",
            describe: "The project name",
        })
            .demandOption(["name", "cert", "key", "environment-type"])
            .check((argv) => {
            validateFileExists(argv.cert, "--cert");
            validateFileExists(argv.key, "--key");
            return true;
        })
            .example([
            [
                "$0 mtls-certificate create --name my_cert --cert ./cert.pem --key ./key.pem --environment-type production",
                "Create an mTLS certificate enabled for the production environment type",
            ],
            [
                "$0 mtls-certificate create --name dev_cert --cert ./cert.pem --key ./key.pem --environment-type development --environment-type preview",
                "Create an mTLS certificate enabled for multiple environment types",
            ],
            [
                "$0 mtls-certificate create --name my_cert --cert ./cert.pem --key ./key.pem --environment-type production --account my-account --project my-project",
                "Explicitly specify the account and project",
            ],
        ])
            .middleware([
            authenticate,
            configure,
            confirmLinkedConfig,
            fetchAccount,
            fetchProject,
            identify,
        ]);
    },
    handler: async (argv) => {
        await captureEvent({ argv, event: "zuplo mtls-certificate create" });
        await create(argv);
    },
};
//# sourceMappingURL=create.js.map