"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cGetAccountDataByListRespVersion = void 0;
exports.serializeGetAccountDataByListResp = serializeGetAccountDataByListResp;
exports.deserializeGetAccountDataByListResp = deserializeGetAccountDataByListResp;
const WrappedData_1 = require("./WrappedData");
const Helpers_1 = require("./ajv/Helpers");
const AJVSchemaEnum_1 = require("./enum/AJVSchemaEnum");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
exports.cGetAccountDataByListRespVersion = 1;
function serializeGetAccountDataByListResp(stream, obj, root = false) {
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.GetAccountDataByListResp, obj);
    if (errors && errors.length > 0) {
        throw new Error('Data validation error');
    }
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cGetAccountDataByListResp);
    }
    stream.writeUInt8(exports.cGetAccountDataByListRespVersion);
    if (obj.accountData !== null) {
        stream.writeUInt8(1);
        stream.writeUInt16(obj.accountData.length);
        for (const item of obj.accountData) {
            (0, WrappedData_1.serializeWrappedData)(stream, item);
        }
    }
    else {
        stream.writeUInt8(0); // Indicate that accountData is null
    }
}
function deserializeGetAccountDataByListResp(stream) {
    const version = stream.readUInt8();
    if (version > exports.cGetAccountDataByListRespVersion) {
        throw new Error('GetAccountDataByListResp version mismatch');
    }
    const accountDataPresent = stream.readUInt8();
    let accountData = null;
    if (accountDataPresent === 1) {
        const length = stream.readUInt16();
        accountData = [];
        for (let i = 0; i < length; i++) {
            accountData.push((0, WrappedData_1.deserializeWrappedData)(stream));
        }
    }
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.GetAccountDataByListResp, accountData);
    if (errors && errors.length > 0) {
        throw new Error('Data validation error');
    }
    return {
        accountData,
    };
}
//# sourceMappingURL=GetAccountDataByListResp.js.map