export var ESP = {};

import {Client} from '@stomp/stompjs';

console.log('Enhanced Services Platform/SDK mk18 (GIPSY DANGER)');

ESP.devtest = function () {
    const client = new Client({
        brokerURL: 'ws://esp1.leigh-co.com:52021/ws',
        debug: function (str) {
            console.log(str);
        },
        reconnectDelay: 5000,
        heartbeatIncoming: 4000,
        heartbeatOutgoing: 4000,
    });

    client.onConnect = function (frame) {
        console.log('stomp connected!');
        client.subscribe('/topic/LC.TELEMETRY', function () {
            console.log('Got message');
        });
        client.publish({destination: '/topic/LC.TELEMETRY', body: 'Hello world'});
    };

    client.onStompError = function (frame) {
        console.log('Broker reported error: ' + frame.headers['message']);
        console.log('Additional details: ' + frame.body);
    };

    client.activate();
}

/**
 * This class holds information about the currently logged in user, if any.
 *
 * @constructor
 */
ESP.ESPPrincipal = function () {
    this._username = 'jsmith';
    this.firstName = 'John';
    this.lastName = 'Smith';
    this.label = 'John Smith';
}

/**
 * Return the end-user's username (login name).
 *
 * This field may be <code>null</code> in the case that this is an anonymous
 * session.
 *
 * Example: "aleigh"
 *
 * @returns {string}
 */
ESP.ESPPrincipal.prototype.getUsername = function () {
    return this._username;
}

/**
 * Return the end-user's first name.
 *
 * This field may be <code>null</code>.
 *
 * Example: "Alex"
 *
 * @returns {*}
 */
ESP.ESPPrincipal.prototype.getFirstName = function () {
    return this._firstName;
}

/**
 * Return the end-user's last name.
 *
 * This field may be <code>null</code>.
 *
 * Example: "Leigh"
 *
 * @returns {*}
 */
ESP.ESPPrincipal.prototype.getLastName = function () {
    return this._lastName;
}

/**
 * Return the end-user's display label. This is their full name, formatted properly.
 *
 * This field may NOT be <code>null</code>.
 *
 * Example: "Alex Leigh"
 *
 * @returns {*}
 */
ESP.ESPPrincipal.prototype.getLabel = function () {
    return this._label;
}