"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SocketMessage = void 0;
const openflow_api_1 = require("@openiap/openflow-api");
function isNumber(value) {
    return ((value != null) && !isNaN(Number(value.toString())));
}
class SocketMessage {
    constructor() {
        this.priority = 1;
    }
    static fromjson(json) {
        let result = new SocketMessage();
        let obj = JSON.parse(json);
        result.command = obj.command;
        result.id = obj.id;
        result.replyto = obj.replyto;
        result.count = 1;
        result.index = 0;
        result.clientagent = obj.clientagent;
        result.clientversion = obj.clientversion;
        if (!openflow_api_1.NoderedUtil.IsNullEmpty(obj.priority))
            result.priority = obj.priority;
        result.data = obj.data;
        if (isNumber(obj.count)) {
            result.count = obj.count;
        }
        if (isNumber(obj.index)) {
            result.index = obj.index;
        }
        if (result.id === null || result.id === undefined || result.id === "") {
            result.id = openflow_api_1.NoderedUtil.GetUniqueIdentifier();
        }
        return result;
    }
    static fromcommand(command) {
        const result = new SocketMessage();
        result.command = command;
        result.count = 1;
        result.index = 0;
        result.id = openflow_api_1.NoderedUtil.GetUniqueIdentifier();
        return result;
    }
    static frommessage(msg, data, count, index) {
        const result = new SocketMessage();
        result.id = msg.id;
        result.replyto = msg.replyto;
        result.command = msg.command;
        result.count = count;
        result.index = index;
        result.data = data;
        return result;
    }
    tojson() {
        return JSON.stringify(this);
    }
}
exports.SocketMessage = SocketMessage;
//# sourceMappingURL=SocketMessage.js.map