"use strict";
/* istanbul ignore file */
/* eslint-disable @typescript-eslint/naming-convention */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTransactionQueueConstructorStub = exports.getPrepareStub = exports.getAddProcedureStub = exports.getAddBatchTransactionStub = exports.getAddTransactionStub = exports.getInstance = exports.reset = exports.cleanup = exports.initMocks = exports.mockTransactionQueueModule = exports.mockProcedureModule = exports.MockTransactionQueueClass = exports.MockProcedureClass = void 0;
const lodash_1 = require("lodash");
const sinon_1 = __importDefault(require("sinon"));
const mockInstanceContainer = {
    procedure: {},
    transactionQueue: {},
};
let procedureConstructorStub;
let transactionQueueConstructorStub;
let addTransactionStub;
let addBatchTransactionStub;
let addProcedureStub;
let prepareStub;
const MockProcedureClass = class {
    /**
     * @hidden
     */
    constructor(...args) {
        return procedureConstructorStub(...args);
    }
};
exports.MockProcedureClass = MockProcedureClass;
const MockTransactionQueueClass = class {
    /**
     * @hidden
     */
    constructor(...args) {
        return transactionQueueConstructorStub(...args);
    }
};
exports.MockTransactionQueueClass = MockTransactionQueueClass;
const mockProcedureModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { Procedure: exports.MockProcedureClass }));
exports.mockProcedureModule = mockProcedureModule;
const mockTransactionQueueModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { TransactionQueue: exports.MockTransactionQueueClass }));
exports.mockTransactionQueueModule = mockTransactionQueueModule;
/**
 * @hidden
 * Initialize the transaction queue instance
 */
function initTransactionQueue() {
    transactionQueueConstructorStub = sinon_1.default.stub();
    const transactionQueue = {};
    Object.assign(mockInstanceContainer.transactionQueue, transactionQueue);
    transactionQueueConstructorStub.callsFake(args => {
        const value = lodash_1.merge({}, transactionQueue, args);
        Object.setPrototypeOf(value, require("../../internal").TransactionQueue.prototype);
        return value;
    });
}
/**
 * @hidden
 * Initialize the procedure instance
 */
function initProcedure() {
    procedureConstructorStub = sinon_1.default.stub();
    addTransactionStub = sinon_1.default.stub();
    addProcedureStub = sinon_1.default.stub();
    addBatchTransactionStub = sinon_1.default.stub();
    prepareStub = sinon_1.default.stub();
    const procedure = {
        addTransaction: addTransactionStub.returns([]),
        addBatchTransaction: addBatchTransactionStub.returns([]),
        addProcedure: addProcedureStub.returns([]),
        prepare: prepareStub.returns({}),
    };
    Object.assign(mockInstanceContainer.procedure, procedure);
    procedureConstructorStub.callsFake(args => {
        const value = lodash_1.merge({}, procedure, args);
        Object.setPrototypeOf(value, require("../../internal").Procedure.prototype);
        return value;
    });
}
/**
 * @hidden
 *
 * Initialize the factory by adding default all-purpose functionality to the mock manager
 */
function initMocks() {
    initProcedure();
    initTransactionQueue();
}
exports.initMocks = initMocks;
/**
 * @hidden
 * Restore instances to their original state
 */
function cleanup() {
    mockInstanceContainer.procedure = {};
    mockInstanceContainer.transactionQueue = {};
}
exports.cleanup = cleanup;
/**
 * @hidden
 * Reinitialize mocks
 */
function reset() {
    cleanup();
    initMocks();
}
exports.reset = reset;
/**
 * @hidden
 * Retrieve a Procedure instance
 */
function getInstance(context, storage) {
    const { procedure } = mockInstanceContainer;
    const value = lodash_1.merge({ context, storage }, procedure);
    Object.setPrototypeOf(value, require("../../internal").Procedure.prototype);
    return value;
}
exports.getInstance = getInstance;
/**
 * @hidden
 * Retrieve the stub of the `addTransaction` method
 */
function getAddTransactionStub() {
    return addTransactionStub;
}
exports.getAddTransactionStub = getAddTransactionStub;
/**
 * @hidden
 * Retrieve the stub of the `addBatchTransaction` method
 */
function getAddBatchTransactionStub() {
    return addBatchTransactionStub;
}
exports.getAddBatchTransactionStub = getAddBatchTransactionStub;
/**
 * @hidden
 * Retrieve the stub of the `addProcedure` method
 */
function getAddProcedureStub() {
    return addProcedureStub;
}
exports.getAddProcedureStub = getAddProcedureStub;
/**
 * @hidden
 * Retrieve the stub of the `prepare` method
 */
function getPrepareStub() {
    return prepareStub;
}
exports.getPrepareStub = getPrepareStub;
/**
 * @hidden
 * Retrieve the stub of the TransactionQueue constructor
 */
function getTransactionQueueConstructorStub() {
    return transactionQueueConstructorStub;
}
exports.getTransactionQueueConstructorStub = getTransactionQueueConstructorStub;
//# sourceMappingURL=procedure.js.map