"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyGetAccountDataReq = exports.deserializeGetAccountDataReq = exports.serializeGetAccountDataReq = void 0;
const utils_1 = require("../utils");
const Helpers_1 = require("./ajv/Helpers");
const AJVSchemaEnum_1 = require("./enum/AJVSchemaEnum");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
const cGetAccountDataReqVersion = 1;
function serializeGetAccountDataReq(stream, inp, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cGetAccountDataReq);
    }
    stream.writeUInt8(cGetAccountDataReqVersion);
    stream.writeString(inp.accountStart);
    stream.writeString(inp.accountEnd);
    stream.writeBigUInt64(BigInt(inp.tsStart));
    stream.writeBigUInt64(BigInt(inp.maxRecords));
    stream.writeBigUInt64(BigInt(inp.offset));
    stream.writeString(inp.accountOffset);
}
exports.serializeGetAccountDataReq = serializeGetAccountDataReq;
function deserializeGetAccountDataReq(stream) {
    const version = stream.readUInt8();
    if (version > cGetAccountDataReqVersion) {
        throw new Error('GetAccountDataReq version mismatch');
    }
    const obj = {
        accountStart: stream.readString(),
        accountEnd: stream.readString(),
        tsStart: Number(stream.readBigUInt64()),
        maxRecords: Number(stream.readBigUInt64()),
        offset: Number(stream.readBigUInt64()),
        accountOffset: stream.readString(),
    };
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.GetAccountDataReq, obj);
    if (errors && errors.length > 0) {
        throw new Error('Data validation error');
    }
    return obj;
}
exports.deserializeGetAccountDataReq = deserializeGetAccountDataReq;
function verifyGetAccountDataReq(obj) {
    if ((0, utils_1.isValidShardusAddress)([obj.accountStart, obj.accountEnd]) === false) {
        /* prettier-ignore */ console.log(`GetAccountDataReq: Invalid accountStart or accountEnd: ${obj.accountStart}, ${obj.accountEnd}`);
        return false;
    }
}
exports.verifyGetAccountDataReq = verifyGetAccountDataReq;
//# sourceMappingURL=GetAccountDataReq.js.map