/*
 * Automatically generated by preplate
 */

goog.provide('{{namespace}}.{{name}}');

goog.require('{{project}}');

goog.require('goog.json');
goog.require('goog.object');

goog.require('prestans.types.Filter');

{% for dependency in dependencies %}
goog.require('{{dependency}}');
{% endfor %}

/**
 * @constructor
 * @extends {prestans.types.Filter}
 * @param {boolean=} opt_defaultValue
*/
{{namespace}}.{{name}} = function(opt_defaultValue) {

    if(!goog.isBoolean(opt_defaultValue))
        opt_defaultValue = false;

{% for attribute in attributes %}
{% if attribute.blueprint_type == 'model' %}
    this.{{attribute.ccif}}_ = new {{namespace}}.{{attribute.model_template}}(opt_defaultValue);
{% elif attribute.blueprint_type == 'array' and attribute.element_template_is_model %}
    this.{{attribute.ccif}}_ = new {{namespace}}.{{attribute.element_template}}(opt_defaultValue);
{% else %}
    this.{{attribute.ccif}}_ = opt_defaultValue;
{% endif %}
{% endfor %}
};
goog.inherits({{namespace}}.{{name}}, prestans.types.Filter);



{% for attribute in attributes %}
/**
 * @private
 */
{{namespace}}.{{name}}.prototype.{{attribute.ccif}}_ = null;
{% endfor %}



/**
 * @const
 * Rewrite map
 */
{{namespace}}.{{name}}.REWRITE_MAP = {
{% for attribute in attributes %}
{% if loop.last %}
    "{{attribute.name}}": "{{attribute.map_name}}"
{% else %}
    "{{attribute.name}}": "{{attribute.map_name}}",
{% endif %}
{% endfor %}
};



{% for attribute in attributes %}
/**
 * @export
 */
{{namespace}}.{{name}}.prototype.enable{{attribute.cc}} = function() {
{% if attribute.blueprint_type == 'model' %}
    this.{{attribute.ccif}}_ = new {{namespace}}.{{attribute.model_template}}(true);
{% elif attribute.blueprint_type == 'array' and attribute.element_template_is_model %}
    this.{{attribute.ccif}}_ = new {{namespace}}.{{attribute.element_template}}(true);
{% else %}
	this.{{attribute.ccif}}_ = true;
{% endif %}
};
{% endfor %}



{% for attribute in attributes %}
/**
 * @export
 */
{{namespace}}.{{name}}.prototype.disable{{attribute.cc}} = function() {
{% if attribute.blueprint_type == 'model' %}
    this.{{attribute.ccif}}_ = new {{namespace}}.{{attribute.model_template}}(false);
{% elif attribute.blueprint_type == 'array' and attribute.element_template_is_model %}
    this.{{attribute.ccif}}_ = new {{namespace}}.{{attribute.element_template}}(false);
{% else %}
	this.{{attribute.ccif}}_ = false;
{% endif %}
};
{% endfor %}



{% for attribute in attributes %}
/**
 * @export
 */
{{namespace}}.{{name}}.prototype.get{{attribute.cc}} = function() {
    return this.{{attribute.ccif}}_;
};
{% endfor %}



{% for attribute in attributes %}
{% if attribute.blueprint_type == 'model' %}
{{namespace}}.{{name}}.prototype.set{{attribute.cc}} = function({{attribute.ccif}}) {
    if({{attribute.ccif}} instanceof {{namespace}}.{{attribute.model_template}})
        this.{{attribute.ccif}}_ = {{attribute.ccif}};
    else
        throw "{{attribute.ccif}} must be of type {{namespace}}.{{attribute.model_template}}";
};
{% elif attribute.blueprint_type == 'array' and attribute.element_template_is_model %}
{{namespace}}.{{name}}.prototype.set{{attribute.cc}} = function({{attribute.ccif}}) {
    if({{attribute.ccif}} instanceof {{namespace}}.{{attribute.element_template}})
        this.{{attribute.ccif}}_ = {{attribute.ccif}};
    else
        throw "{{attribute.ccif}} must be of type {{namespace}}.{{attribute.element_template}}";
};
{% endif %}
{% endfor %}



/**
 * @export
 */
{{namespace}}.{{name}}.prototype.anyFieldsEnabled = function() {
    return ({{attribute_string}});
};



/**
 * @export
 * @param {boolean} minified
 * @param {boolean=} opt_complete
 */
{{namespace}}.{{name}}.prototype.getJSONObject = function(minified, opt_complete) {

    if(opt_complete != true)
        opt_complete = false;

    var jsonifiedObject_ = {};
    
    if(goog.isDef(minified) && goog.isBoolean(minified) && minified) {
    {% for attribute in attributes %}
    {% if attribute.blueprint_type == 'model' %}
        if(this.{{attribute.ccif}}_ != null && !goog.object.isEmpty(this.{{attribute.ccif}}_.getJSONObject(minified, opt_complete)))
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.{{attribute.ccif}}_.getJSONObject(minified, opt_complete);
        else if(opt_complete)
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = false;
    {% elif attribute.blueprint_type == 'array' and attribute.element_template_is_model %}
        if(this.{{attribute.ccif}}_ instanceof prestans.types.Filter && opt_complete)
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.{{attribute.ccif}}_.getJSONObject(minified, opt_complete);
        else if(this.{{attribute.ccif}}_ instanceof prestans.types.Filter && !opt_complete && this.{{attribute.ccif}}_.anyFieldsEnabled())
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.{{attribute.ccif}}_.getJSONObject(minified);
        else if(opt_complete)
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = false;
    {% else %}
        if(this.{{attribute.ccif}}_ || opt_complete)
           jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.{{attribute.ccif}}_;
    {% endif %}
    {% endfor %}
    }
    else {
    {% for attribute in attributes %}
    {% if attribute.blueprint_type == 'model' %}
        if(this.{{attribute.ccif}}_ != null && !goog.object.isEmpty(this.{{attribute.ccif}}_.getJSONObject(minified, opt_complete)))
            jsonifiedObject_["{{attribute.name}}"] = this.{{attribute.ccif}}_.getJSONObject(minified, opt_complete);
        else if(opt_complete)
            jsonifiedObject_["{{attribute.name}}"] = false;
    {% elif attribute.blueprint_type == 'array' and attribute.element_template_is_model %}
        if(this.{{attribute.ccif}}_ instanceof prestans.types.Filter && opt_complete)
            jsonifiedObject_["{{attribute.name}}"] = this.{{attribute.ccif}}_.getJSONObject(minified, opt_complete);
        else if(this.{{attribute.ccif}}_ instanceof prestans.types.Filter && !opt_complete && this.{{attribute.ccif}}_.anyFieldsEnabled())
            jsonifiedObject_["{{attribute.name}}"] = this.{{attribute.ccif}}_.getJSONObject(minified);
        else if(opt_complete)
            jsonifiedObject_["{{attribute.name}}"] = false;
    {% else %}
        if(this.{{attribute.ccif}}_ || opt_complete)
           jsonifiedObject_["{{attribute.name}}"] = this.{{attribute.ccif}}_;
    {% endif %}
    {% endfor %}
    }

    return jsonifiedObject_;
};


/**
 * @export
 * @param {boolean} minified
 * @param {boolean=} opt_complete
 */
{{namespace}}.{{name}}.prototype.getJSONString = function(minified, opt_complete) {

    if(opt_complete != true)
        opt_complete = false;

    return goog.json.serialize(this.getJSONObject(minified, opt_complete));
};
