'use strict';

/**
 * Broadcast module used for broadcasting information accross the application.
 * Including:
 *   Broadcast
 */

angular.module('system.services.broadcast', [
    'config.services'
])
    .service('Broadcast', [
        '$rootScope',
        'Config',
        function($rootScope, Config) {
            var info = function(value) {
                broadcast(Config.SYSTEM_INFO_KEY, value);
            };

            var warning = function(value) {
                broadcast(Config.SYSTEM_WARNING_KEY, value);
            };

            var error = function(value) {
                broadcast(Config.SYSTEM_ERROR_KEY, value);
            };

            var success = function(value) {
                broadcast(Config.SYSTEM_SUCCESS_KEY, value);
            };

            var broadcast = function(key, value) {
                $rootScope.$broadcast(key, value);
            };

            var on = function(scope, key, fn) {
                scope.$on(key, fn);
            };

            return {
                info: info,
                warning: warning,
                success: success,
                error: error,
                broadcast: broadcast,
                on: on
            };
        }
    ]);