const awscli = require("./awscli");
const azurecli = require("./azurecli");
const db = require("./mongo");


async function deallocate(provId, isSendEmailAfter ) {
    try {
        let provision = await db.provision.getById(provId);
        if ( !provision ) return;

        if (provision.scenario === 'azqmi-fort'){
            return awscli.deallocate(provision, isSendEmailAfter);
        } else {
            return azurecli.deallocate(provision, isSendEmailAfter);
        }
    } catch (err) {
        console.log("CLI# ERROR stopping VMs", err);
    }
}

async function start(provId){
    
    try {
        let provision = await db.provision.getById(provId);
        if ( !provision ) return;

        if (provision.scenario === 'azqmi-fort'){
            return awscli.start(provision);
        } else {
            return azurecli.start(provision);
        }
    } catch (err) {
        console.log("CLI# ERROR starting VMs", err);
    }
}

async function updateVmsTags(provId, tagsEdit) {
    try {
        return azurecli.updateVmsTags(provId, tagsEdit);
    } catch (err) {
        console.log("CLI# ERROR updateVmsTags", err);
    }
}

module.exports.deallocate = deallocate;
module.exports.start = start;
module.exports.updateVmsTags = updateVmsTags;