/// class ProspectDirector.Web.UI.Queries.ConditionCollection
/// using ProspectDirector.Web.List

ProspectDirector.Web.UI.Queries.ConditionCollection = ProspectDirector.Web.List.extend({

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

    _condition: null,

    //================================
    // CONSTRUCTOR
    //================================

    init: function (options) {

        var that = this;

        this._super(options.data);
        this._condition = options.condition;
        this.each(function (index, condition) {
            condition._parent = that._condition;
        });

    },

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

    add: function (item) {
        item._parent = this._condition;
        this._super(item);
    },

    insert: function (item, index) {
        item._parent = this._condition;
        this._super(item, index);
    },

    remove: function (item) {
        item._parent = null;
        return this._super(item);
    },

    findById: function (id) {

        var result = null;

        this.each(function (index, condition) {
            if (condition.get_id() === id) {
                result = condition;
                return false;
            }
        });

        if (!result) {

            this.each(function (index, condition) {
                result = condition.findById(id);
                if (result) {
                    return false;
                }
            });

        }

        return result;
    },

    toJSON: function () {

        var result = this.transform(function (item) {
            return item.toJSON();
        });

        return result.toArray();

    }

});