import { captureEvent } from "../../common/analytics/lib.js";
import { authenticate } from "../../common/middleware/authentication.js";
import { identify } from "../../common/middleware/user-identification.js";
import setBlocking from "../../common/output.js";
import { create } from "../../project/create/handler.js";
import { configure } from "../../common/middleware/user-configuration.js";
import { fetchAccount } from "../../common/middleware/get-account-param.js";
import { input } from "@inquirer/prompts";
export default {
    desc: "Creates a new project in your account",
    command: "create",
    builder: (yargs) => {
        return yargs
            .option("name", {
            type: "string",
            describe: "The name of the project to create",
        })
            .option("api-key", {
            type: "string",
            describe: "The API Key from Zuplo",
            envVar: "API_KEY",
        })
            .middleware([
            setBlocking,
            authenticate,
            configure,
            fetchAccount,
            identify,
        ]);
    },
    handler: async (argv) => {
        if (!argv || typeof argv !== "object") {
            throw new Error("Invalid state: name is not set. Please provide a project name.");
        }
        const args = argv;
        if (!args.name) {
            args.name = await input({
                message: "Enter the project name: ",
            });
            if (!args.name) {
                throw new Error("Invalid state: name is not set. Please provide a project name.");
            }
        }
        await captureEvent({ argv, event: "zuplo project create" });
        await create(args);
    },
};
//# sourceMappingURL=create.js.map