"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeGetAccountDataByHashesResp = exports.serializeGetAccountDataByHashesResp = exports.cGetAccountDataByHashesRespVersion = void 0;
const Helpers_1 = require("./ajv/Helpers");
const AJVSchemaEnum_1 = require("./enum/AJVSchemaEnum");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
const WrappedData_1 = require("./WrappedData");
exports.cGetAccountDataByHashesRespVersion = 1;
const serializeGetAccountDataByHashesResp = (stream, inp, root = false) => {
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.GetAccountDataByHashesResp, inp);
    if (errors && errors.length > 0) {
        throw new Error('Data validation error');
    }
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cGetAccountDataByHashesResp);
    }
    stream.writeUInt8(exports.cGetAccountDataByHashesRespVersion);
    stream.writeUInt32(inp.accounts.length || 0);
    /* eslint-disable security/detect-object-injection */
    for (let i = 0; i < inp.accounts.length; i++) {
        (0, WrappedData_1.serializeWrappedData)(stream, inp.accounts[i]);
    }
    stream.writeUInt32(inp.stateTableData.length || 0);
    for (let i = 0; i < inp.stateTableData.length; i++) {
        stream.writeString(inp.stateTableData[i].accountId);
        stream.writeString(inp.stateTableData[i].txId);
        stream.writeString(inp.stateTableData[i].txTimestamp);
        stream.writeString(inp.stateTableData[i].stateBefore);
        stream.writeString(inp.stateTableData[i].stateAfter);
    }
    /* eslint-enable security/detect-object-injection */
};
exports.serializeGetAccountDataByHashesResp = serializeGetAccountDataByHashesResp;
const deserializeGetAccountDataByHashesResp = (stream) => {
    const version = stream.readUInt8();
    if (version !== exports.cGetAccountDataByHashesRespVersion) {
        throw new Error(`GetAccountDataByHashesRespDeserializer expected version ${exports.cGetAccountDataByHashesRespVersion}, got ${version}`);
    }
    const result = {
        accounts: [],
        stateTableData: [],
    };
    const accountsLength = stream.readUInt32();
    for (let i = 0; i < accountsLength; i++) {
        result.accounts.push((0, WrappedData_1.deserializeWrappedData)(stream));
    }
    const stateTableDataLength = stream.readUInt32();
    for (let i = 0; i < stateTableDataLength; i++) {
        result.stateTableData.push({
            accountId: stream.readString(),
            txId: stream.readString(),
            txTimestamp: stream.readString(),
            stateBefore: stream.readString(),
            stateAfter: stream.readString(),
        });
    }
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.GetAccountDataByHashesResp, result);
    if (errors && errors.length > 0) {
        throw new Error('Data validation error');
    }
    return result;
};
exports.deserializeGetAccountDataByHashesResp = deserializeGetAccountDataByHashesResp;
//# sourceMappingURL=GetAccountDataByHashesResp.js.map