import { CONSTANTS } from '../interface/exported';

/**
 * @observable
 * helps get values in attributes
 *
 */
export function observable(options?: any) {

    // get passed in options //todo, create interface
    let _options: any;
    _options = options;

    return function (target: any, key: any) {

        if (!target[CONSTANTS.META_BINDABLE]) {
            target[CONSTANTS.META_BINDABLE] = {};
        }


        // check if attribute is added
        if (options) {
            if (!options.attribute) {
                options.attribute = null;
            }
        }

        // check if key is added, if not add
        if (!target[CONSTANTS.META_BINDABLE][key]) {
            target[CONSTANTS.META_BINDABLE][key] = {
                key: key,
                observableOnly : true,
                options: _options || {
                    attribute: null
                }
            };
        }

    };
}
