"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const mablApiClientFactory_1 = require("@mablhq-internal/runtime/api/mablApiClientFactory");
const util_1 = require("../../commandUtil/util");
const cliUtil_1 = require("@mablhq-internal/runtime/core/cliUtil");
const describe_1 = require("../../commandUtil/describe");
const constants_1 = require("@mablhq-internal/runtime/core/constants");
const constants_2 = require("../../constants");
exports.command = 'describe <identifier>';
exports.describe = 'Describe a specific mabl branch by id or name';
exports.builder = (yargs) => {
    yargs
        .positional('identifier', {
        describe: 'The branch ID or NAME to describe',
        type: 'string',
        nargs: 1,
        demand: 'Branch identifier is required',
    })
        .option(constants_2.CommandArgName, {
        alias: constants_2.CommandArgAliases.Name,
        describe: 'Use identifier as Get branch based on name',
        type: 'boolean',
        default: false,
    })
        .option(constants_2.CommandArgOutput, {
        alias: constants_2.CommandArgAliases.OutputType,
        describe: 'Specify an output type for the branch data',
        choices: constants_2.DefaultOutputFormatChoices,
    })
        .option(constants_1.CommandArgWorkspaceId, {
        alias: constants_2.CommandArgAliases.WorkspaceId,
        describe: 'The workspace ID to create a new branch',
        nargs: 1,
        type: 'string',
    });
};
exports.handler = (0, cliUtil_1.failWrapper)(getBranch);
async function getBranch(parsed) {
    const branchIdentifier = parsed.identifier;
    const lookupByName = parsed.name;
    const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
    let branch;
    if (lookupByName) {
        const workspaceId = await (0, util_1.getWorkspaceId)(parsed);
        branch = await apiClient.getBranchByName(workspaceId, branchIdentifier);
    }
    else {
        branch = await apiClient.getBranchById(branchIdentifier);
    }
    (0, describe_1.outputEntity)(branch, parsed.output);
    return branch.id;
}
