"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWarningMessage = exports.getBareMetalHost = exports.getBareMetalHostCredentialsSecret = void 0;
const common_1 = require("../common");
const getBareMetalHostCredentialsSecret = (values, namespace) => ({
    apiVersion: 'v1',
    kind: 'Secret',
    data: {
        username: btoa(values.username),
        password: btoa(values.password),
    },
    metadata: {
        generateName: `bmc-${values.hostname.split('.').shift() || ''}-`,
        namespace,
    },
    type: 'Opaque',
});
exports.getBareMetalHostCredentialsSecret = getBareMetalHostCredentialsSecret;
const getBareMetalHost = (values, infraEnv, secret) => {
    var _a, _b, _c;
    return ({
        apiVersion: 'metal3.io/v1alpha1',
        kind: 'BareMetalHost',
        metadata: {
            name: values.name,
            namespace: (_a = infraEnv.metadata) === null || _a === void 0 ? void 0 : _a.namespace,
            labels: {
                [common_1.INFRAENV_AGENTINSTALL_LABEL_KEY]: ((_b = infraEnv.metadata) === null || _b === void 0 ? void 0 : _b.name) || '',
            },
            annotations: {
                'inspect.metal3.io': 'disabled',
                [common_1.BMH_HOSTNAME_ANNOTATION]: values.hostname,
            },
        },
        spec: {
            bmc: {
                address: values.bmcAddress,
                credentialsName: ((_c = secret.metadata) === null || _c === void 0 ? void 0 : _c.name) || '',
                disableCertificateVerification: !!values.disableCertificateVerification,
            },
            bootMACAddress: values.bootMACAddress,
            description: '', // TODO(mlibra)
            online: !!values.online,
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-ignore
            automatedCleaningMode: 'disabled', // TODO is it a left-over and can be deleted? not in the Type
        },
    });
};
exports.getBareMetalHost = getBareMetalHost;
const getWarningMessage = (hasAgents, hasBMHs, t) => {
    if (hasBMHs && hasAgents) {
        return t('ai:The resource you are changing is already in use by hosts in the infrastructure environment. A change will require booting the hosts with a new discovery ISO file. Hosts will be rebooted automatically after the change is applied if using BMC.');
    }
    else if (hasBMHs) {
        return t('ai:The resource you are changing is already in use by hosts in the infrastructure environment. The hosts will be rebooted automatically after the change is applied.');
    }
    else if (hasAgents) {
        return t('ai:The resource you are changing is already in use by hosts in the infrastructure environment. A change will require booting the hosts with a new discovery ISO file.');
    }
    else {
        return t('ai:A change will require booting hosts with a new discovery ISO file.');
    }
};
exports.getWarningMessage = getWarningMessage;
//# sourceMappingURL=utils.js.map