/// class ProspectDirector.Web.UI.FeatureSets.ValidationErrorCollection
/// using ProspectDirector.Web.List


/**
[NEEDS DOCUMENTATION]
@constructor
@class ValidationErrorCollection
@namespace Web.UI.FeatureSets
**/
ProspectDirector.Web.UI.FeatureSets.ValidationErrorCollection = ProspectDirector.Web.List.extend({

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

    getFeatureBound: function (featureType) {

        var that = this,
            result = new ProspectDirector.Web.UI.FeatureSets.ValidationErrorCollection();

        this.each(function (index, item) {

            if (featureType) {
                if (that._isMatch(item, featureType)) {
                    result.add(item);
                }
            }
            else {
                if (item.get_propertyName() === null) {
                    result.add(item);
                }
            }

        });

        return result;

    },

    getByFeatureTypeAndPropertyName: function (featureType, propertyName) {

        var that = this,
            result = new ProspectDirector.Web.UI.FeatureSets.ValidationErrorCollection();

        this.getByFeatureType(featureType).each(function (index, item) {
            if (that._isMatch(item, featureType, propertyName)) {
                result.add(item);
            };
        });

        return result;

    },

    getByFeatureType: function (featureType) {

        var that = this,
            result = new ProspectDirector.Web.UI.FeatureSets.ValidationErrorCollection();

        this.each(function (index, item) {

            if (item.get_featureType() === featureType) {
                result.add(item);
            };

        });

        return result;

    },

    getByGroupId: function (groupId) {

        var that = this,
            result = new ProspectDirector.Web.UI.FeatureSets.ValidationErrorCollection();

        this.each(function (index, item) {

            if (item.get_groupId() === groupId) {
                result.add(item);
            };

        });

        return result;

    },

    getGroupIds: function () {

        var that = this,
            result = new ProspectDirector.Web.List();

        this.each(function (index, item) {

            if (!result.contains(item.get_groupId())) {
                result.add(item.get_groupId());
            };

        });

        return result;

    },

    //==============================
    // PRIVATE METHODS
    //==============================

    _isMatch: function (item, featureType, propertyName) {

        var result = false,
            itemFeatureType = item.get_featureType() || "",
            itemPropertyName = item.get_propertyName() || "";

        featureType = featureType || "";
        propertyName = propertyName || "";

        result = itemFeatureType.toLowerCase() === featureType.toLowerCase()
            && itemPropertyName.toLowerCase() === propertyName.toLowerCase();

        return result;

    }

});