/*!
 * ASP.NET SignalR JavaScript Library 2.4.3
 * http://signalr.net/
 *
 * Copyright (c) .NET Foundation. All rights reserved.
 * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 *
 */

/// <reference path="..\..\SignalR.Client.JS\Scripts\jquery-1.6.4.js" />
/// <reference path="jquery.signalR.js" />
(function ($, window, undefined) {
    /// <param name="$" type="jQuery" />
    "use strict";

    if (typeof ($.signalR) !== "function") {
        throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.");
    }

    var signalR = $.signalR;

    function makeProxyCallback(hub, callback) {
        return function () {
            // Call the client hub method
            callback.apply(hub, $.makeArray(arguments));
        };
    }

    function registerHubProxies(instance, shouldSubscribe) {
        var key, hub, memberKey, memberValue, subscriptionMethod;

        for (key in instance) {
            if (instance.hasOwnProperty(key)) {
                hub = instance[key];

                if (!(hub.hubName)) {
                    // Not a client hub
                    continue;
                }

                if (shouldSubscribe) {
                    // We want to subscribe to the hub events
                    subscriptionMethod = hub.on;
                } else {
                    // We want to unsubscribe from the hub events
                    subscriptionMethod = hub.off;
                }

                // Loop through all members on the hub and find client hub functions to subscribe/unsubscribe
                for (memberKey in hub.client) {
                    if (hub.client.hasOwnProperty(memberKey)) {
                        memberValue = hub.client[memberKey];

                        if (!$.isFunction(memberValue)) {
                            // Not a client hub function
                            continue;
                        }

                        // Use the actual user-provided callback as the "identity" value for the registration.
                        subscriptionMethod.call(hub, memberKey, makeProxyCallback(hub, memberValue), memberValue);
                    }
                }
            }
        }
    }

    $.hubConnection.prototype.createHubProxies = function () {
        var proxies = {};
        this.starting(function () {
            // Register the hub proxies as subscribed
            // (instance, shouldSubscribe)
            registerHubProxies(proxies, true);

            this._registerSubscribedHubs();
        }).disconnected(function () {
            // Unsubscribe all hub proxies when we "disconnect".  This is to ensure that we do not re-add functional call backs.
            // (instance, shouldSubscribe)
            registerHubProxies(proxies, false);
        });

        proxies['smartertrackhub'] = this.createHubProxy('smartertrackhub'); 
        proxies['smartertrackhub'].client = { };
        proxies['smartertrackhub'].server = {
            agentInit: function () {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["AgentInit"], $.makeArray(arguments)));
             },

            agentSetAfk: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["AgentSetAfk"], $.makeArray(arguments)));
             },

            chatAgentJoin: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatAgentJoin"], $.makeArray(arguments)));
             },

            chatAgentLogin: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatAgentLogin"], $.makeArray(arguments)));
             },

            chatAgentSendMessage: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatAgentSendMessage"], $.makeArray(arguments)));
             },

            chatAgentSetTyping: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatAgentSetTyping"], $.makeArray(arguments)));
             },

            chatCheckStatus: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatCheckStatus"], $.makeArray(arguments)));
             },

            chatConfirmPopupOpened: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatConfirmPopupOpened"], $.makeArray(arguments)));
             },

            chatSetLastReadMessage: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatSetLastReadMessage"], $.makeArray(arguments)));
             },

            chatTakeOwnership: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatTakeOwnership"], $.makeArray(arguments)));
             },

            chatTransfer: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatTransfer"], $.makeArray(arguments)));
             },

            chatUpdateStatus: function (chatStatus) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatUpdateStatus"], $.makeArray(arguments)));
             },

            chatUserJoin: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatUserJoin"], $.makeArray(arguments)));
             },

            chatUserPing: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatUserPing"], $.makeArray(arguments)));
             },

            chatUserSendMessage: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatUserSendMessage"], $.makeArray(arguments)));
             },

            chatUserSetTyping: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["ChatUserSetTyping"], $.makeArray(arguments)));
             },

            dashboardSubscribe: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["DashboardSubscribe"], $.makeArray(arguments)));
             },

            dashboardUnsubscribe: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["DashboardUnsubscribe"], $.makeArray(arguments)));
             },

            dashboardUnsubscribeFromAll: function () {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["DashboardUnsubscribeFromAll"], $.makeArray(arguments)));
             },

            dashboardUnsubscribeGuid: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["DashboardUnsubscribeGuid"], $.makeArray(arguments)));
             },

            dBConversionSetCompleted: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["DBConversionSetCompleted"], $.makeArray(arguments)));
             },

            enteredTicket: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["EnteredTicket"], $.makeArray(arguments)));
             },

            joinLoginAlertRooms: function () {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["JoinLoginAlertRooms"], $.makeArray(arguments)));
             },

            leftTicket: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["LeftTicket"], $.makeArray(arguments)));
             },

            ping: function (input) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["Ping"], $.makeArray(arguments)));
             },

            subscribeToCallLogListChanges: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["SubscribeToCallLogListChanges"], $.makeArray(arguments)));
             },

            subscribeToTaskListChanges: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["SubscribeToTaskListChanges"], $.makeArray(arguments)));
             },

            subscribeToTicketCountUpdate: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["SubscribeToTicketCountUpdate"], $.makeArray(arguments)));
             },

            subscribeToTicketListChanges: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["SubscribeToTicketListChanges"], $.makeArray(arguments)));
             },

            taskTreeSubscribe: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["TaskTreeSubscribe"], $.makeArray(arguments)));
             },

            taskTreeUnsubscribe: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["TaskTreeUnsubscribe"], $.makeArray(arguments)));
             },

            unsubscribeFromCallLogListChanges: function () {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["UnsubscribeFromCallLogListChanges"], $.makeArray(arguments)));
             },

            unsubscribeFromTaskListChanges: function () {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["UnsubscribeFromTaskListChanges"], $.makeArray(arguments)));
             },

            unsubscribeFromTicketCountUpdate: function (packet) {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["UnsubscribeFromTicketCountUpdate"], $.makeArray(arguments)));
             },

            unsubscribeFromTicketListChanges: function () {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["UnsubscribeFromTicketListChanges"], $.makeArray(arguments)));
             },

            whosOnSubscribe: function () {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["WhosOnSubscribe"], $.makeArray(arguments)));
             },

            whosOnUnsubscribe: function () {
                return proxies['smartertrackhub'].invoke.apply(proxies['smartertrackhub'], $.merge(["WhosOnUnsubscribe"], $.makeArray(arguments)));
             }
        };

        return proxies;
    };

    signalR.hub = $.hubConnection("/signalr", { useDefaultPath: false });
    $.extend(signalR, signalR.hub.createHubProxies());

}(window.jQuery, window));
