"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyPayload = exports.initAjvSchemas = void 0;
const lib_types_1 = require("@shardeum-foundation/lib-types");
const SchemaHelpers_1 = require("../../utils/serialization/SchemaHelpers");
const ApoptosisProposalReq_1 = require("./ApoptosisProposalReq");
const ApoptosisProposalResp_1 = require("./ApoptosisProposalResp");
const BroadcastStateReq_1 = require("./BroadcastStateReq");
const CachedAppData_1 = require("./CachedAppData");
const CompareCert_1 = require("./CompareCert");
const GetAccountData3Req_1 = require("./GetAccountData3Req");
const GetAccountDataByHashesReq_1 = require("./GetAccountDataByHashesReq");
const GetAccountDataByHashesResp_1 = require("./GetAccountDataByHashesResp");
const GetAccountDataByListReq_1 = require("./GetAccountDataByListReq");
const GetAccountDataByListResp_1 = require("./GetAccountDataByListResp");
const GetAccountDataResp_1 = require("./GetAccountDataResp");
const GetAccountDataWithQueueHintsReq_1 = require("./GetAccountDataWithQueueHintsReq");
const GetAccountDataWithQueueHintsResp_1 = require("./GetAccountDataWithQueueHintsResp");
const GetAccountQueueCountReq_1 = require("./GetAccountQueueCountReq");
const GetAccountQueueCountResp_1 = require("./GetAccountQueueCountResp");
const GetAppliedVoteReq_1 = require("./GetAppliedVoteReq");
const GetAppliedVoteResp_1 = require("./GetAppliedVoteResp");
const GetCachedAppDataReq_1 = require("./GetCachedAppDataReq");
const GetCachedAppDataResp_1 = require("./GetCachedAppDataResp");
const GetTrieAccountHashesReq_1 = require("./GetTrieAccountHashesReq");
const GetTrieAccountHashesResp_1 = require("./GetTrieAccountHashesResp");
const GetTrieHashesReq_1 = require("./GetTrieHashesReq");
const GetTrieHashesResp_1 = require("./GetTrieHashesResp");
const GetTxTimestampReq_1 = require("./GetTxTimestampReq");
const GetTxTimestampResp_1 = require("./GetTxTimestampResp");
const GlobalAccountReportReq_1 = require("./GlobalAccountReportReq");
const GlobalAccountReportResp_1 = require("./GlobalAccountReportResp");
const LostReportReq_1 = require("./LostReportReq");
const MakeReceiptReq_1 = require("./MakeReceiptReq");
const SignAppDataReq_1 = require("./SignAppDataReq");
const SignAppDataResp_1 = require("./SignAppDataResp");
const RepairOOSAccountsReq_1 = require("./RepairOOSAccountsReq");
const RequestReceiptForTxReq_1 = require("./RequestReceiptForTxReq");
const RequestReceiptForTxResp_1 = require("./RequestReceiptForTxResp");
const RequestStateForTxPostReq_1 = require("./RequestStateForTxPostReq");
const RequestStateForTxPostResp_1 = require("./RequestStateForTxPostResp");
const RequestStateForTxReq_1 = require("./RequestStateForTxReq");
const RequestStateForTxResp_1 = require("./RequestStateForTxResp");
const sendCachedAppDataReq_1 = require("./sendCachedAppDataReq");
const SpreadAppliedVoteHashReq_1 = require("./SpreadAppliedVoteHashReq");
const SpreadTxToGroupSyncingReq_1 = require("./SpreadTxToGroupSyncingReq");
const SyncTrieHashesReq_1 = require("./SyncTrieHashesReq");
const WrappedData_1 = require("./WrappedData");
const WrappedDataFromQueueSerializable_1 = require("./WrappedDataFromQueueSerializable");
const WrappedDataResponse_1 = require("./WrappedDataResponse");
const CycleRecordSchema_1 = require("./CycleRecordSchema");
const JoinReq_1 = require("./JoinReq");
const AllowedArchiverResponse_1 = require("./AllowedArchiverResponse");
function initAjvSchemas() {
    (0, GetAccountData3Req_1.initGetAccountData3Req)();
    (0, CompareCert_1.initCompareCertReq)();
    (0, SpreadTxToGroupSyncingReq_1.initSpreadTxToGroupSyncingReq)();
    (0, ApoptosisProposalReq_1.initApoptosisProposalReq)();
    (0, ApoptosisProposalResp_1.initApoptosisProposalResp)();
    (0, GetTxTimestampReq_1.initGetTxTimestampReq)();
    (0, GetTxTimestampResp_1.initGetTxTimestampResp)();
    (0, WrappedData_1.initWrappedData)();
    (0, GetAccountDataByListReq_1.initGetAccountDataByListReq)();
    (0, GetAccountDataByListResp_1.initGetAccountDataByListResp)();
    (0, GetAccountDataByHashesReq_1.initGetAccountDataByHashesReq)();
    (0, GetAccountDataByHashesResp_1.initGetAccountDataByHashesResp)();
    (0, RepairOOSAccountsReq_1.initRepairOOSAccountReq)();
    (0, RequestStateForTxReq_1.initRequestStateForTxReq)();
    (0, RequestStateForTxResp_1.initRequestStateForTxResp)();
    (0, RequestReceiptForTxReq_1.initRequestReceiptForTxReq)();
    (0, RequestReceiptForTxResp_1.initRequestReceiptForTxResp)();
    (0, GetAppliedVoteReq_1.initGetAppliedVoteReq)();
    (0, GetAppliedVoteResp_1.initGetAppliedVoteResp)();
    (0, LostReportReq_1.initLostReportReq)();
    (0, RequestStateForTxPostReq_1.initRequestStateForTxPostReq)();
    (0, RequestStateForTxPostResp_1.initRequestStateForTxPostResp)();
    (0, WrappedDataResponse_1.initWrappedDataResponse)();
    (0, BroadcastStateReq_1.initBroadcastStateReq)();
    (0, GetAccountDataResp_1.initGetAccountDataRespSerializable)();
    (0, GetCachedAppDataReq_1.initGetCachedAppDataReq)();
    (0, GetCachedAppDataResp_1.initGetCachedAppDataResp)();
    (0, GetTrieAccountHashesReq_1.initGetTrieAccountHashesReq)();
    (0, GetTrieAccountHashesResp_1.initGetTrieAccountHashesResp)();
    (0, WrappedDataFromQueueSerializable_1.initWrappedDataFromQueueSerializable)();
    (0, GetAccountDataWithQueueHintsReq_1.initGetAccountDataWithQueueHintsReq)();
    (0, GetAccountDataWithQueueHintsResp_1.initGetAccountDataWithQueueHintsResp)();
    (0, SpreadAppliedVoteHashReq_1.initSpreadAppliedVoteHashReq)();
    (0, GlobalAccountReportReq_1.initGlobalAccountReportReq)();
    (0, GlobalAccountReportResp_1.initGlobalAccountReportResp)();
    (0, SyncTrieHashesReq_1.initSyncTrieHashesReq)();
    (0, GetAccountQueueCountReq_1.initGetAccountQueueCountReq)();
    (0, GetAccountQueueCountResp_1.initGetAccountQueueCountResp)();
    (0, MakeReceiptReq_1.initMakeReceiptReq)();
    (0, GetTrieHashesReq_1.initGetTrieHashesReq)();
    (0, GetTrieHashesResp_1.initGetTrieHashesResp)();
    (0, SignAppDataReq_1.initSignAppDataReq)();
    (0, SignAppDataResp_1.initSignAppDataResp)();
    (0, CachedAppData_1.initCachedAppData)();
    (0, sendCachedAppDataReq_1.initSendCachedAppDataReq)();
    (0, CycleRecordSchema_1.initCycleRecords)();
    (0, JoinReq_1.initJoinReq)();
    (0, AllowedArchiverResponse_1.initAllowedArchiverResponse)();
}
exports.initAjvSchemas = initAjvSchemas;
function verifyPayload(name, payload) {
    const verifyFn = (0, SchemaHelpers_1.getVerifyFunction)(name);
    const isValid = verifyFn(payload);
    if (!isValid) {
        return parseAjvErrors(verifyFn.errors);
    }
    else {
        return null;
    }
}
exports.verifyPayload = verifyPayload;
function parseAjvErrors(errors) {
    if (!errors)
        return null;
    return errors.map((error) => {
        let errorMsg = `${error.message}`;
        if (error.params && Object.keys(error.params).length > 0) {
            errorMsg += `: ${lib_types_1.Utils.safeStringify(error.params)}`;
        }
        return errorMsg;
    });
}
//# sourceMappingURL=Helpers.js.map