module.exports = function () {
    var createProps = function (classInstance, resources) {
        for (let property in resources) {
            if (Object.prototype.hasOwnProperty.call(resources, property)) {
                if (!classInstance[property])
                    classInstance[property] = ko.observable();
            }
        }
    }
    var fillForm = function (classInstance, model, excludeList) {
        for (let property in model) {
            if (Object.prototype.hasOwnProperty.call(model, property)) {
                if (!excludeList || excludeList.indexOf(property) === -1) {
                    var value = ko.isObservable(model[property]) ? model[property]() : model[property];
                    if (!Array.isArray(model[property]()))
                        classInstance[property] = ko.observable(value);
                    if (Array.isArray(model[property]()))
                        classInstance[property] = ko.observableArray(value);
                }

            }
        }
    }
    var fillModel = function (classInstance, model,) {
        for (let property in model) {
            if (Object.prototype.hasOwnProperty.call(model, property)) {
                if (!classInstance[property] && !Array.isArray(model[property]))
                    classInstance[property] = ko.observable(model[property]);
                else if (!classInstance[property] && Array.isArray(model[property]))
                    classInstance[property] = ko.observableArray(model[property]);
                else
                    classInstance[property](model[property]);
            }
        }
    }
    var fillInfoModel = function (classInstance, model) {
        for (let property in model) {
            if (Object.prototype.hasOwnProperty.call(model, property)) {
                classInstance[property] = model[property];
            }
        }
    }
    var createPropsFromList = function (classInstance, paramList) {
        if (_h.any(paramList))
            for (let i = 0; i < paramList.length; i++) {
                let param = paramList[i];
                let value;
                switch (param.type) {
                    case "":
                        value = undefined;
                        if (!_h.isNullOrEmpty(param["def"]))
                            value = param["def"];
                        if (!_h.isNullOrEmpty(param["val"]))
                            value = param["val"];
                        classInstance[param.name] = value;
                        break;
                    case "obar":
                        value = [];
                        if (!_h.isNullOrEmpty(param["def"]))
                            value = param["def"];
                        if (!_h.isNullOrEmpty(param["val"]))
                            value = param["val"];
                        classInstance[param.name] = ko.observableArray(value);
                        break;
                    case "ar":
                        value = [];
                        if (!_h.isNullOrEmpty(param["def"]))
                            value = param["def"];
                        if (!_h.isNullOrEmpty(param["val"]))
                            value = param["val"];
                        classInstance[param.name] = value;
                        break;
                    case "ob":
                        value = undefined;
                        if (!_h.isNullOrEmpty(param["def"]))
                            value = param["def"];
                        if (!_h.isNullOrEmpty(param["val"]))
                            value = param["val"];
                        classInstance[param.name] = ko.observable(value);
                        break;
                }
            }
    }
    return {
        fillInfoModel: fillInfoModel,
        fillForm: fillForm,
        createProps: createProps,
        createPropsFromList: createPropsFromList,
        fillModel: fillModel
    };
}();
