import { logger } from "../logger.js";
import { printDiagnosticsToConsole, textOrJson } from "../output.js";
import settings from "../settings.js";
export async function validateFleet(argv) {
    const account = argv.account;
    const fleet = argv.fleet;
    const authToken = argv.authToken;
    if (!account || typeof account !== "string") {
        logger.error("Missing or invalid required parameter: account");
        printDiagnosticsToConsole("Error: Missing required parameter 'account'.");
        process.exit(1);
    }
    if (!fleet || typeof fleet !== "string") {
        logger.error("Missing or invalid required parameter: fleet");
        printDiagnosticsToConsole("Error: Missing required parameter 'fleet'.");
        process.exit(1);
    }
    try {
        const fleetResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/fleets/${fleet}`, {
            method: "GET",
            headers: {
                Authorization: `Bearer ${authToken}`,
            },
        });
        if (fleetResponse.ok) {
            return;
        }
        if (fleetResponse.status === 404) {
            const response = textOrJson(await fleetResponse.text());
            logger.error({
                status: fleetResponse.status,
                statusText: fleetResponse.statusText,
                response,
            }, "Fleet does not exist");
            printDiagnosticsToConsole(`Error: Fleet '${fleet}' does not exist for account '${account}'.`);
            process.exit(1);
        }
        const response = textOrJson(await fleetResponse.text());
        logger.error({
            status: fleetResponse.status,
            statusText: fleetResponse.statusText,
            response,
        }, "Failed to validate fleet existence");
        printDiagnosticsToConsole("Error: Failed to validate fleet existence. Check your authentication and permissions.", response);
        process.exit(1);
    }
    catch (error) {
        logger.error({ error }, "Network error while validating fleet");
        printDiagnosticsToConsole("Error: Network error while validating fleet existence.");
        process.exit(1);
    }
}
//# sourceMappingURL=validate-fleet.js.map