"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalMachineResourceConfigurator = void 0;
const tslib_1 = require("tslib");
const inversify_1 = require("inversify");
const codiac_common_1 = require("@codiac.io/codiac-common");
const codiac_ops_common_1 = require("@codiac.io/codiac-ops-common");
const codiac_relay_1 = require("../../apis/codiac-relay");
const contracts_1 = require("../../apis/codiac-api/contracts");
const ops_1 = require("../../ops");
const resource_configurator_base_1 = require("../shared/resource-configurator-base");
// import { CspPrimaryCredsMeta, LogintoCloudProviderRequest } from "../../apis/codiac-relay/contracts";
// import { ICspLoginOptions } from "../../sdk";
let LocalMachineResourceConfigurator = class LocalMachineResourceConfigurator extends resource_configurator_base_1.ResourceConfiguratorBase {
    constructor(codiacUser, genRelayClient, _ui, _styler, logger) {
        super(codiacUser, genRelayClient, _ui, _styler, logger);
    }
    get cloudProvider() {
        return contracts_1.CloudProviderEnum.localMachine;
    }
    // /* ***********************************************************************************
    //  *    ___        _   _     
    //  *   / _ \      | | | |    
    //  *  / /_\ \_   _| |_| |__  
    //  *  |  _  | | | | __| '_ \ 
    //  *  | | | | |_| | |_| | | |
    //  *  \_| |_/\__,_|\__|_| |_|
    //  * 
    //  * ***********************************************************************************/
    // public async promptToLogin(options?: ICspLoginOptions): Promise<[boolean, CspPrimaryCredsMeta]> {
    //   this.logger.debug("No login required for ".concat(this.cloudProvider));
    //   const cspUser = <CspPrimaryCredsMeta>{
    //     provider: this.cloudProvider,
    //     subscriptionId: "subx-placeholder-for-localMachine",
    //     tenantCode: this.codiacUser.tenantCode,
    //     username: options?.providedUserName ?? this.codiacUser.username,
    //     created: new Date(Date.now())
    //   }
    //   return [true, cspUser];
    // }
    // public async promptToLogout(): Promise<[boolean, string]> {
    //   const cspUserName = this.codiacUser.username;
    //   return [true, cspUserName];  // Just a pass-through.  No authentication required for localMachine.
    // }
    // assembleLoginRequest(user: string | undefined, secret: string | undefined, subscriptionId: string | undefined, proprietaryInput: { [key: string]: any; }): LogintoCloudProviderRequest {
    //   return <LogintoCloudProviderRequest>{
    //     providerCode: this.cloudProvider,
    //     providerSubscription: subscriptionId,
    //     username: user,
    //     secret: secret
    //   }
    // }
    /* ***********************************************************************************
    *   _____ _           _
    *  /  __ \ |         | |
    *  | /  \/ |_   _ ___| |_ ___ _ __
    *  | |   | | | | / __| __/ _ \ '__|
    *  | \__/\ | |_| \__ \ ||  __/ |
    *   \____/_|\__,_|___/\__\___|_|
    *
    *  ***********************************************************************************/
    defineCluster(initial, defaults) {
        var _a;
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            let output;
            try {
                let workingModel = {};
                workingModel.provider = this.cloudProvider;
                workingModel.privateOwner = this.codiacUser.tenantCode;
                [initial, defaults] = yield this.applyClusterDefaults(workingModel, initial, defaults);
                workingModel.thisMachine = true;
                workingModel.locationName = "localMachine";
                workingModel.providerSubscription = "not-applicable";
                workingModel.providerGroup = "not-applicable";
                workingModel.nodeSpec = "not-applicable";
                workingModel.startingNodeCount = 1;
                workingModel.name = yield this.promptForName(initial === null || initial === void 0 ? void 0 : initial.name);
                // TODO: Set default from AKS (mark it in list, too)
                // TODO: ask to change before prompting the list
                workingModel.k8sVersion = yield this.promptForK8sVersion(workingModel.locationName, workingModel.providerSubscription, initial === null || initial === void 0 ? void 0 : initial.k8sVersion);
                let spec = Object.assign({ name: workingModel.name, provider: workingModel.provider, providerSubscription: workingModel.providerSubscription, locationName: workingModel.locationName, providerGroup: workingModel.providerGroup, nodeCount: workingModel.nodeCount, ingressDef: workingModel.ingressDef, privateOwner: workingModel.privateOwner, nodeSpec: workingModel.nodeSpec, startingNodeCount: workingModel.startingNodeCount, identitySpec: (_a = workingModel.identitySpec) !== null && _a !== void 0 ? _a : { type: contracts_1.SecurityAccountTypeEnum.servicePrincipal, name: "" } }, this.createAuditable());
                spec.k8sVersion = workingModel.k8sVersion;
                if (workingModel.nodePools)
                    spec.nodePools = workingModel.nodePools;
                if (workingModel.defaultFootprint)
                    spec.defaultFootprint = workingModel.defaultFootprint;
                if (workingModel.startingNodeCount)
                    spec.startingNodeCount = workingModel.startingNodeCount;
                if (workingModel.subnet)
                    spec.subnet = workingModel.subnet;
                if (workingModel.windowsAdmin)
                    spec.windowsAdmin = workingModel.windowsAdmin;
                if (workingModel.identityInstance)
                    spec.identityInstance = workingModel.identityInstance;
                if (workingModel.thisMachine)
                    spec.thisMachine = workingModel.thisMachine;
                return { spec: spec, defaults: defaults };
            }
            catch (err) {
                throw err;
            }
        });
    }
    defineClusterCaptureParams(initial, rootMap, defaults) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            throw new Error("Capture of clusters on the local machine is not yet supported.");
        });
    }
    promptForIngressSpec(current) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            throw new Error("Method not implemented.");
        });
    }
};
LocalMachineResourceConfigurator = tslib_1.__decorate([
    (0, inversify_1.injectable)(),
    tslib_1.__param(0, (0, inversify_1.inject)(codiac_ops_common_1.UserNameTenantCode)),
    tslib_1.__param(1, (0, inversify_1.inject)(codiac_relay_1.RelayClient)),
    tslib_1.__param(2, (0, inversify_1.inject)(ops_1.INTERFACES_CLI.IUserInputProvider)),
    tslib_1.__param(3, (0, inversify_1.inject)(ops_1.INTERFACES_CLI.IOutputStyler)),
    tslib_1.__param(4, (0, inversify_1.inject)(codiac_common_1.INTERFACES.IBetterLogger)),
    tslib_1.__metadata("design:paramtypes", [codiac_ops_common_1.UserNameTenantCode,
        codiac_relay_1.RelayClient, Object, Object, Object])
], LocalMachineResourceConfigurator);
exports.LocalMachineResourceConfigurator = LocalMachineResourceConfigurator;
//# sourceMappingURL=local-machine-resource-configurator.js.map