"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cGetAccountQueueCountRespVersion = void 0;
exports.serializeGetAccountQueueCountResp = serializeGetAccountQueueCountResp;
exports.deserializeGetAccountQueueCountResp = deserializeGetAccountQueueCountResp;
const Context_1 = require("../p2p/Context");
const Helpers_1 = require("./ajv/Helpers");
const AJVSchemaEnum_1 = require("./enum/AJVSchemaEnum");
const AppObjEnum_1 = require("./enum/AppObjEnum");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
exports.cGetAccountQueueCountRespVersion = 1;
function serializeGetAccountQueueCountResp(stream, obj, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cGetAccountQueueCountResp);
    }
    stream.writeUInt8(exports.cGetAccountQueueCountRespVersion);
    if (obj === false) {
        stream.writeUInt8(0);
    }
    else {
        stream.writeUInt8(1);
        stream.writeUInt16(obj.counts.length);
        obj.counts.forEach((count) => stream.writeUInt32(count));
        stream.writeUInt16(obj.committingAppData.length);
        obj.committingAppData.forEach((data) => stream.writeBuffer(Context_1.stateManager.app.binarySerializeObject(AppObjEnum_1.AppObjEnum.AppData, data)));
        stream.writeUInt16(obj.accounts.length);
        obj.accounts.forEach((account) => stream.writeBuffer(Context_1.stateManager.app.binarySerializeObject(AppObjEnum_1.AppObjEnum.AppData, account)));
    }
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cGetAccountQueueCountResp);
    }
}
function deserializeGetAccountQueueCountResp(stream) {
    const version = stream.readUInt8();
    if (version > exports.cGetAccountQueueCountRespVersion) {
        throw new Error('GetAccountQueueCountResp version mismatch');
    }
    const typeIndicator = stream.readUInt8();
    if (typeIndicator === 0) {
        return false;
    }
    else {
        const countsLength = stream.readUInt16();
        const counts = [];
        for (let i = 0; i < countsLength; i++) {
            counts.push(stream.readUInt32());
        }
        const committingAppDataLength = stream.readUInt16();
        const committingAppData = [];
        for (let i = 0; i < committingAppDataLength; i++) {
            committingAppData.push(Context_1.stateManager.app.binaryDeserializeObject(AppObjEnum_1.AppObjEnum.AppData, stream.readBuffer()));
        }
        const accountsLength = stream.readUInt16();
        const accounts = [];
        for (let i = 0; i < accountsLength; i++) {
            accounts.push(Context_1.stateManager.app.binaryDeserializeObject(AppObjEnum_1.AppObjEnum.AppData, stream.readBuffer()));
        }
        const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.GetAccountQueueCountResp, {
            counts,
            committingAppData,
            accounts,
        });
        if (errors && errors.length > 0) {
            throw new Error('Data validation error');
        }
        return {
            counts,
            committingAppData,
            accounts,
        };
    }
}
//# sourceMappingURL=GetAccountQueueCountResp.js.map