/// class ProspectDirector.Web.UI.FeatureSets.Feature

/**
@constructor
@class Web.UI.FeatureSets.Feature
**/
ProspectDirector.Web.UI.FeatureSets.Feature = Class.extend({

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

    _options: null,

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

    init: function (options) {
        this._options = options;
        this._fill(options.data);
    },

    //==============================
    // PROPERTIES
    //==============================

    /**
    @public
    @property get_binding 
    @type {String}
    **/
    get_binding: function () {
        return this.get_data().binding;
    },

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

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

    /**
    @public
    @property get_options 
    @type {Object}
    **/
    get_options: function () {
        return this._options;
    },

    /**
    @public
    @property get_parent
    @type {Web.UI.FeatureSets.FeatureSetGroup}
    **/
    get_parent: function () {
        return this.get_options().parent;
    },

    /**
    @public
    @property get_featureSet 
    @type {Web.UI.FeatureSets.FeatureSet}
    **/
    get_featureSet: function () {
        return this.get_parent().get_featureSet();
    },

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

    /**
    @public
    @method getData 
    @return {Object} A dictionary of key/value pairs representing the data passed to the feature.
    **/
    getData: function () {
        return this.get_options().data;
    },

    /**
    @public
    @method getDataKeys 
    @return {Web.List}
    **/
    getDataKeys: function () {

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

        for (key in keys) {
            result.add(key);
        }

        return result;

    },

    /**
    @public
    @method setValue
    @param key {String} The key to use to store the value supplied.
    @param value {Object} The value to store.
    **/
    setValue: function (key, value) {

        var result = false,
            currentValue = null;

        if (this.get_data().hasOwnProperty(key)) {

            currentValue = this.get_data()[key];

            if (currentValue !== value) {

                this.get_featureSet().trigger("change", {
                    key: key,
                    oldValue: this.get_data()[key],
                    newValue: value
                });

            };

            this.get_data()[key] = value;

            result = true;

        }
        else {
            throw "Property \"" + (key || "") + "\" cannot be set.";
        }

        return result;

    },

    /**
    @public
    @method getValue 
    @param key {String} The key to use to find the value to be retrieved.
    @return {Object} The value retrieved from the data structure found using the key provided. If the value cannot be found using the key provided `undefined` is returned.
    **/
    getValue: function (key) {

        if (this.get_data().hasOwnProperty(key)) {
            return this.get_data()[key];
        }
        else {
            throw "Property \"" + (key || "") + "\" does not exist.";
        }

    },
    
    /**
    @public
    @method save
    **/
    save: function () {
        //do nothing on purpose
    },

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

    /**
    @private
    @method _fill
    **/
    _fill: function (data) {
    }

});