"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DlcMessage = void 0;
const bufio_1 = require("@node-dlc/bufio");
const MessageType_1 = require("../MessageType");
const ContractDescriptor_1 = require("./ContractDescriptor");
const ContractInfo_1 = require("./ContractInfo");
const DlcAccept_1 = require("./DlcAccept");
const DlcClose_1 = require("./DlcClose");
const DlcOffer_1 = require("./DlcOffer");
const DlcSign_1 = require("./DlcSign");
const NodeAnnouncementMessage_1 = require("./NodeAnnouncementMessage");
const OracleAnnouncement_1 = require("./OracleAnnouncement");
const OracleAttestation_1 = require("./OracleAttestation");
const OrderAccept_1 = require("./OrderAccept");
const OrderOffer_1 = require("./OrderOffer");
class DlcMessage {
    static deserialize(buf) {
        const reader = new bufio_1.BufferReader(buf);
        const type = reader.readUInt16BE();
        switch (type) {
            case MessageType_1.MessageType.ContractDescriptorV0:
                return ContractDescriptor_1.EnumeratedDescriptor.deserialize(buf);
            case MessageType_1.MessageType.ContractDescriptorV1:
                return ContractDescriptor_1.NumericalDescriptor.deserialize(buf);
            case MessageType_1.MessageType.SingleContractInfo:
                return ContractInfo_1.SingleContractInfo.deserialize(buf);
            case MessageType_1.MessageType.DisjointContractInfo:
                return ContractInfo_1.DisjointContractInfo.deserialize(buf);
            case MessageType_1.MessageType.OrderOffer:
                return OrderOffer_1.OrderOffer.deserialize(buf);
            case MessageType_1.MessageType.OrderAccept:
                return OrderAccept_1.OrderAccept.deserialize(buf);
            case MessageType_1.MessageType.DlcOffer:
                return DlcOffer_1.DlcOffer.deserialize(buf);
            case MessageType_1.MessageType.DlcAccept:
                return DlcAccept_1.DlcAccept.deserialize(buf);
            case MessageType_1.MessageType.DlcSign:
                return DlcSign_1.DlcSign.deserialize(buf);
            case MessageType_1.MessageType.DlcClose:
                return DlcClose_1.DlcClose.deserialize(buf);
            case MessageType_1.MessageType.OracleAttestation:
                return OracleAttestation_1.OracleAttestation.deserialize(buf);
            case MessageType_1.MessageType.OracleAnnouncement:
                return OracleAnnouncement_1.OracleAnnouncement.deserialize(buf);
            case MessageType_1.MessageType.NodeAnnouncement:
                return NodeAnnouncementMessage_1.NodeAnnouncementMessage.deserialize(buf);
            default:
                throw new Error(`DlcMessage type ${type} not supported`);
        }
    }
}
exports.DlcMessage = DlcMessage;
//# sourceMappingURL=DlcMessage.js.map