import { readFileSync } from "node:fs";
import { createApiClient } from "../../common/api/client.js";
import { logger } from "../../common/logger.js";
import { printDiagnosticsToConsole, printResultToConsoleAndExitGracefully, } from "../../common/output.js";
export async function create(argv) {
    const { account, fleet } = argv;
    let configData;
    try {
        const fileContent = readFileSync(argv["configuration-file"], "utf-8");
        configData = JSON.parse(fileContent);
    }
    catch (error) {
        logger.error({ error }, `Failed to read or parse configuration file: ${argv["configuration-file"]}`);
        printDiagnosticsToConsole(`Error: Failed to read or parse configuration file: ${argv["configuration-file"]}`);
        process.exit(1);
    }
    const client = createApiClient({ authToken: argv.authToken });
    await client.put(`/v1/accounts/${account}/fleets/${fleet}/proxy-configuration`, {
        operation: "Failed to create proxy configuration",
        errorMessage: "Error: Failed to create proxy configuration. Check the arguments and configuration file.",
        body: configData,
        emptyResponse: true,
    });
    await printResultToConsoleAndExitGracefully(`Successfully created proxy configuration for fleet ${fleet}`);
}
//# sourceMappingURL=handler.js.map