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