"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeGetAccountDataByHashesReq = exports.serializeGetAccountDataByHashesReq = exports.cGetAccountDataByHashesReqVersion = void 0;
const Helpers_1 = require("./ajv/Helpers");
const AJVSchemaEnum_1 = require("./enum/AJVSchemaEnum");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
exports.cGetAccountDataByHashesReqVersion = 1;
const serializeGetAccountDataByHashesReq = (stream, inp, root = false) => {
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.GetAccountDataByHashesReq, inp);
    if (errors && errors.length > 0) {
        throw new Error('Data validation error');
    }
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cGetAccountDataByHashesReq);
    }
    stream.writeUInt8(exports.cGetAccountDataByHashesReqVersion);
    stream.writeBigUInt64(BigInt(inp.cycle));
    stream.writeUInt32(inp.accounts.length || 0);
    for (let i = 0; i < inp.accounts.length; i++) {
        // eslint-disable-next-line security/detect-object-injection
        stream.writeString(inp.accounts[i].accountID);
        // eslint-disable-next-line security/detect-object-injection
        stream.writeString(inp.accounts[i].hash);
    }
};
exports.serializeGetAccountDataByHashesReq = serializeGetAccountDataByHashesReq;
const deserializeGetAccountDataByHashesReq = (stream) => {
    const version = stream.readUInt8();
    if (version !== exports.cGetAccountDataByHashesReqVersion) {
        throw new Error(`GetAccountDataByHashesReqDeserializer expected version ${exports.cGetAccountDataByHashesReqVersion}, got ${version}`);
    }
    const cycleNumber = Number(stream.readBigUInt64());
    const accountsLength = stream.readUInt32();
    const result = {
        cycle: cycleNumber,
        accounts: [],
    };
    for (let i = 0; i < accountsLength; i++) {
        result.accounts.push({
            accountID: stream.readString(),
            hash: stream.readString(),
        });
    }
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.GetAccountDataByHashesReq, result);
    if (errors && errors.length > 0) {
        throw new Error('Data validation error');
    }
    return result;
};
exports.deserializeGetAccountDataByHashesReq = deserializeGetAccountDataByHashesReq;
//# sourceMappingURL=GetAccountDataByHashesReq.js.map