/* Generated from Java with JSweet 2.3.7 - http://www.jsweet.org */
import { ModelUtils } from '../util/ModelUtils';
import { NodeCompat } from '../../compat/NodeCompat';
/**
 * @author eric.wittmann@gmail.com
 * @class
 */
var SimplifiedType = /** @class */ (function () {
    function SimplifiedType() {
        if (this.type === undefined)
            this.type = null;
        if (this.enum_ === undefined)
            this.enum_ = null;
        if (this.of === undefined)
            this.of = null;
        if (this.as === undefined)
            this.as = null;
    }
    SimplifiedType.__static_initialize = function () { if (!SimplifiedType.__static_initialized) {
        SimplifiedType.__static_initialized = true;
        SimplifiedType.__static_initializer_0();
    } };
    SimplifiedType.VALID_TYPES_$LI$ = function () { SimplifiedType.__static_initialize(); if (SimplifiedType.VALID_TYPES == null)
        SimplifiedType.VALID_TYPES = ([]); return SimplifiedType.VALID_TYPES; };
    ;
    SimplifiedType.__static_initializer_0 = function () {
        /* add */ (SimplifiedType.VALID_TYPES_$LI$().push("string") > 0);
        /* add */ (SimplifiedType.VALID_TYPES_$LI$().push("number") > 0);
        /* add */ (SimplifiedType.VALID_TYPES_$LI$().push("integer") > 0);
        /* add */ (SimplifiedType.VALID_TYPES_$LI$().push("boolean") > 0);
    };
    SimplifiedType.fromParameter = function (param) {
        var rval = new SimplifiedType();
        if (ModelUtils.isDefined(param) && ModelUtils.isDefined(param.enum_) && /* size */ param.enum_.length >= 0) {
            rval.enum_ = (param.enum_.slice(0));
        }
        if (ModelUtils.isDefined(param) && ModelUtils.isDefined(param.type) && !NodeCompat.equals(param.type, "array") && !NodeCompat.equals(param.type, "object")) {
            rval.type = param.type;
            if (ModelUtils.isDefined(param.format)) {
                rval.as = param.format;
            }
        }
        if (ModelUtils.isDefined(param) && NodeCompat.equals(param.type, "array") && ModelUtils.isDefined(param.items)) {
            rval.type = "array";
            rval.of = SimplifiedType.fromItems(param.items);
        }
        return rval;
    };
    SimplifiedType.fromItems = function (items) {
        var rval = new SimplifiedType();
        if (ModelUtils.isDefined(items) && ModelUtils.isDefined(items.enum_) && /* size */ items.enum_.length >= 0) {
            rval.enum_ = (items.enum_.slice(0));
        }
        if (ModelUtils.isDefined(items) && ModelUtils.isDefined(items.type) && !NodeCompat.equals(items.type, "array") && !NodeCompat.equals(items.type, "object")) {
            rval.type = items.type;
            if (ModelUtils.isDefined(items.format)) {
                rval.as = items.format;
            }
        }
        if (ModelUtils.isDefined(items) && NodeCompat.equals(items.type, "array") && ModelUtils.isDefined(items.items)) {
            rval.type = "array";
            rval.of = SimplifiedType.fromItems(items.items);
        }
        return rval;
    };
    SimplifiedType.fromSchema = function (schema) {
        var rval = new SimplifiedType();
        if (ModelUtils.isDefined(schema) && ModelUtils.isDefined(schema.$ref)) {
            rval.type = schema.$ref;
        }
        if (ModelUtils.isDefined(schema) && ModelUtils.isDefined(schema.enum_) && /* size */ schema.enum_.length >= 0) {
            rval.enum_ = (schema.enum_.slice(0));
        }
        if (ModelUtils.isDefined(schema) && ModelUtils.isDefined(schema.type) && !NodeCompat.equals(schema.type, "array") && !NodeCompat.equals(schema.type, "object")) {
            rval.type = schema.type;
            if (ModelUtils.isDefined(schema.format)) {
                rval.as = schema.format;
            }
        }
        if (ModelUtils.isDefined(schema) && NodeCompat.equals(schema.type, "array") && ModelUtils.isDefined(schema.items)) {
            rval.type = "array";
            rval.of = SimplifiedType.fromSchema(schema.items);
        }
        return rval;
    };
    SimplifiedType.prototype.isSimpleType = function () {
        return SimplifiedType.VALID_TYPES_$LI$().indexOf(this.type) !== -1;
    };
    SimplifiedType.prototype.isFileType = function () {
        return NodeCompat.equals(this.type, "file");
    };
    SimplifiedType.prototype.isEnum = function () {
        return ModelUtils.isDefined(this.enum_) && /* size */ this.enum_.length >= 0;
    };
    SimplifiedType.prototype.isArray = function () {
        return NodeCompat.equals(this.type, "array");
    };
    SimplifiedType.prototype.isRef = function () {
        return ModelUtils.isDefined(this.type) && this.type.indexOf("#/") === 0;
    };
    SimplifiedType.__static_initialized = false;
    return SimplifiedType;
}());
export { SimplifiedType };
SimplifiedType["__class"] = "io.apicurio.datamodels.cmd.models.SimplifiedType";
SimplifiedType.__static_initialize();
//# sourceMappingURL=SimplifiedType.js.map