"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cWrappedDataResponseVersion = void 0;
exports.serializeWrappedDataResponse = serializeWrappedDataResponse;
exports.deserializeWrappedDataResponse = deserializeWrappedDataResponse;
const WrappedData_1 = require("./WrappedData");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
const Helpers_1 = require("./ajv/Helpers");
const AJVSchemaEnum_1 = require("./enum/AJVSchemaEnum");
exports.cWrappedDataResponseVersion = 1;
function serializeWrappedDataResponse(stream, obj, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cWrappedDataResponse);
    }
    stream.writeUInt8(exports.cWrappedDataResponseVersion);
    (0, WrappedData_1.serializeWrappedData)(stream, obj);
    stream.writeUInt8(obj.accountCreated ? 1 : 0);
    stream.writeUInt8(obj.isPartial ? 1 : 0);
}
function deserializeWrappedDataResponse(stream) {
    const version = stream.readUInt8();
    if (version > exports.cWrappedDataResponseVersion) {
        throw new Error('WrappedDataResponse version mismatch');
    }
    const wrappedData = (0, WrappedData_1.deserializeWrappedData)(stream);
    const accountCreated = stream.readUInt8() !== 0;
    const isPartial = stream.readUInt8() !== 0;
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.WrappedDataResponse, {
        ...wrappedData,
        accountCreated,
        isPartial,
    });
    if (errors && errors.length > 0) {
        throw new Error('Data validation error');
    }
    return {
        ...wrappedData,
        accountCreated,
        isPartial,
    };
}
//# sourceMappingURL=WrappedDataResponse.js.map