{% import 'closure/filter/macro.jinja' as filter %}
/**
 * Automatically generated by pride
 */
goog.provide('{{namespace}}.{{name}}');

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

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

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

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

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

{% for attribute in attributes %}
{{filter.attributeDefinition(namespace, name, attribute)}}
{% endfor %}
};
goog.inherits({{namespace}}.{{name}}, prestans.types.Filter);

/**
 * Rewrite map
 * @enum {!string}
 */
{{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 %}
{{filter.enableMethod(namespace, name, attribute)}}

{% endfor %}

{% for attribute in attributes %}
{{filter.disableMethod(namespace, name, attribute)}}

{% endfor %}

{% for attribute in attributes %}
{{filter.getMethod(namespace, name, attribute)}}

{% endfor %}

{% for attribute in attributes %}
{% if attribute.blueprint_type == 'model' or (attribute.blueprint_type == 'array' and attribute.element_template_is_model) %}
{{filter.setMethod(namespace, name, attribute)}}
{% endif %}
{% endfor %}

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

/**
 * @final
 * @param {!boolean} minified
 * @param {!boolean=} opt_complete
 *
 * @return {!Object}
 */
{{namespace}}.{{name}}.prototype.getJSONObject = function(minified, opt_complete) {

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

    var jsonifiedObject_ = {};
    
    if(goog.isDef(minified) && goog.isBoolean(minified) && minified) {
    {% for attribute in attributes %}
    {{filter.minifiedAttribute(namespace, name, attribute)}}
    {% 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_;
};

/**
 * @final
 * @param {!boolean} minified
 * @param {!boolean=} opt_complete
 *
 * @return {!string}
 */
{{namespace}}.{{name}}.prototype.getJSONString = function(minified, opt_complete) {
    return goog.json.serialize(this.getJSONObject(minified, opt_complete));
};
