"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArgumentPersistence = void 0;
const internal_1 = require("../../internal");
const utils = require("./utils");
class ArgumentPersistence {
    static fromData(ctx, object) {
        const argument = ctx.corpus.MakeObject(internal_1.cdmObjectType.argumentDef);
        // must use `object != undefined` here, since when object is null, null != undefined => false but null !== undefined => true
        if (typeof object === 'object' && object != undefined && object.value !== undefined) {
            argument.value = utils.createConstant(ctx, object.value);
            if (object.name) {
                argument.name = object.name;
            }
            if (object.explanation) {
                argument.explanation = object.explanation;
            }
        }
        else {
            // not a structured argument, just a thing. try it
            argument.value = utils.createConstant(ctx, object);
        }
        return argument;
    }
    static toData(instance, resOpt, options) {
        let value;
        if (instance.value !== undefined) {
            if (typeof (instance.value) === 'object' && 'copyData' in instance.value
                && typeof (instance.value.copyData) === 'function') {
                value = instance.value.copyData(resOpt, options);
            }
            else {
                value = instance.value;
            }
        }
        // skip the argument if just a value
        if (internal_1.StringUtils.isBlankByCdmStandard(instance.name)) {
            return value;
        }
        return { explanation: instance.explanation, name: instance.name, value: value };
    }
}
exports.ArgumentPersistence = ArgumentPersistence;
//# sourceMappingURL=ArgumentPersistence.js.map