import { logger } from "../../common/logger.js";
import { printDiagnosticsToConsole, printResultToConsole, textOrJson, } from "../../common/output.js";
import settings from "../../common/settings.js";
export async function create(argv) {
    const { account, project } = argv;
    const createResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/projects/${project}/branches/${encodeURIComponent(argv["branch"])}/variables`, {
        method: "POST",
        headers: {
            Authorization: `Bearer ${argv.authToken}`,
            "Content-Type": "application/json",
        },
        body: JSON.stringify({
            name: argv["name"],
            isSecret: argv["is-secret"],
            value: argv["value"],
        }),
    });
    if (createResponse.ok) {
        const variable = await createResponse.json();
        printResultToConsole(`${variable.name} created successfully`);
    }
    else {
        const problem = textOrJson(await createResponse.text());
        logger.error({
            status: createResponse.status,
            statusText: createResponse.statusText,
            response: problem,
        }, "Failed to create variable");
        printDiagnosticsToConsole("Error: Failed to create variable. Check the arguments.", problem);
    }
}
//# sourceMappingURL=handler.js.map