ProspectDirector.Web.UI.Queries.Filter = Class.extend({

    //================================
    // FIELDS
    //================================

    _conditions: null,
    _filters: null,
    _parent: null,

    //================================
    // CONSTRCUTOR
    //================================

    init: function (options) {

        options = $.extend(true, {}, {
            data: {
                id: uuid.v4(),
                autoValueId: null,
                autoValueName: null,
                columnId: null,
                columnName: null,
                isEnabled: true,
                operatorId: 0,
                operatorName: "No Filter Set",
                role: "filter",
                scalarFunctionId: null,
                scalarFunctionName: null,
                useAutoValue: false,
                value: null,
                verse: null
            }
        }, options);

        ProspectDirector.Web.Structure.mixin(options.data, this);

        this.data("checked", this.data("isEnabled"));
        this.data("useAutoValue", this.data("autoValueId") !== null);

    },

    //================================
    // CONSTRCUTOR
    //================================

    get_id: function () {
        return this.data("id");
    },

    get_autoValueId: function () {
        return this.data("autoValueId");
    },

    get_autoValueName: function () {
        return this.data("autoValueName");
    },

    get_columnId: function () {
        return this.data("columnId");
    },

    get_columnName: function () {
        return this.data("columnName");
    },

    get_isEnabled: function () {
        return this.data("isEnabled");
    },

    get_operatorId: function () {
        return this.data("operatorId");
    },

    get_operatorName: function () {
        return this.data("operatorName");
    },

    get_parent: function () {
        return this._parent;
    },

    get_role: function () {
        return this.data("role");
    },

    get_scalarFunctionId: function () {
        return this.data("scalarFunctionId");
    },

    get_scalarFunctionName: function () {
        return this.data("scalarFunctionName");
    },

    get_useAutoValue: function () {
        return this.data("useAutoValue");
    },

    get_value: function () {
        return this.data("value");
    },

    get_verse: function () {
        return this.data("verse");
    },

    //================================
    // PUBLIC METHODS
    //================================

    isFirst: function () {
        return this.get_parent() === null
            || this.get_parent().get_filters().first().get_id() === this.get_id();
    },

    isLast: function () {
        return this.get_parent() === null
            || this.get_parent().get_filters().last().get_id() === this.get_id();
    },

    remove: function () {
        if (this.get_parent()) {
            this.get_parent().get_filters().remove(this);
        }
    },

    update: function (data) {
        return this.data().update(data);
    },

    toJSON: function () {
        return this.data().toObject();
    }

});