(function () {
    'use strict';
    angular.module('ti_common').service('ufSearch', ufSearch);
    ufSearch.$inject = [];
    function ufSearch() {
        var searchStr = '';
        var searchEntry = [];
        var observerCallbacks = [];
        function getResultList() {
            return searchEntry;
        }
        function addSearchEntry(type, content, action) {
            searchEntry.push({ 'type': type, 'content': content, 'action': action });
        }
        //register an observer
        function registerObserverCallback(callback) {
            observerCallbacks.push(callback);
        }
        function updateSearchResults(sStr) {
            searchEntry = [];
            if (sStr) {
                notifyObservers(sStr);
            }
        }
        function notifyObservers(sStr) {
            _.each(observerCallbacks, function (callback) {
                callback(sStr);
            });
        }
        return {
            searchStr: searchStr,
            getResultList: getResultList,
            addSearchEntry: addSearchEntry,
            registerObserverCallback: registerObserverCallback,
            updateSearchResults: updateSearchResults
        };
    }
})();
