"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDividendDistributionInstance = exports.getCorporateActionInstance = exports.getCheckpointScheduleInstance = exports.getCheckpointInstance = exports.getOfferingInstance = exports.getInstructionInstance = exports.getKnownPermissionGroupInstance = exports.getCustomPermissionGroupInstance = exports.getDefaultPortfolioInstance = exports.getNumberedPortfolioInstance = exports.getVenueInstance = exports.getAuthorizationRequestInstance = exports.getAssetInstance = exports.getTickerReservationInstance = exports.getSubsidyInstance = exports.getAccountInstance = exports.getIdentityInstance = exports.reset = exports.configureMocks = exports.initMocks = exports.mockKnownPermissionGroupModule = exports.mockCustomPermissionGroupModule = exports.mockDividendDistributionModule = exports.mockCorporateActionModule = exports.mockCheckpointScheduleModule = exports.mockCheckpointModule = exports.mockOfferingModule = exports.mockDefaultPortfolioModule = exports.mockNumberedPortfolioModule = exports.mockInstructionModule = exports.mockVenueModule = exports.mockAuthorizationRequestModule = exports.mockAssetModule = exports.mockTickerReservationModule = exports.mockSubsidyModule = exports.mockAccountModule = exports.mockIdentityModule = void 0;
/* istanbul ignore file */
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable @typescript-eslint/no-explicit-any */
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const lodash_1 = require("lodash");
const sinon_1 = __importDefault(require("sinon"));
const types_1 = require("../../types");
/* eslint-disable @typescript-eslint/ban-types */
/**
 * @hidden
 */
function extractFromArgs(args, properties) {
    if (args.length) {
        return lodash_1.pick(args[0], properties);
    }
    return {};
}
/* eslint-enable @typescript-eslint/ban-types */
/**
 * @hidden
 *
 * @param prototypeChain - inheritance chain of the entity, from broad to specific.
 *   For example, if creating a mock for class A, where A extends B, B extends C and C extends Entity,
 *   the prototypeChain would be [C, B, A]
 */
function createMockEntityClass(Class, defaultOptions, prototypeChain) {
    var _a;
    const initialOptions = (options) => (Object.assign(Object.assign({ isEqual: true, exists: true, toJson: 'DEFAULT_JSON_STRING_PLEASE_OVERRIDE' }, defaultOptions()), options));
    return _a = class MockClass extends Class {
            /**
             * @hidden
             */
            constructor(...args) {
                super(...args);
                this.isEqual = sinon_1.default.stub();
                this.exists = sinon_1.default.stub();
                this.toJson = sinon_1.default.stub();
                let opts = {};
                if (this.argsToOpts) {
                    opts = this.argsToOpts(...args);
                }
                MockClass.constructorStub(...args);
                this.configure(opts);
            }
            /**
             * @hidden
             */
            static mergeOptions(options) {
                return Object.assign(Object.assign({}, this.options), options);
            }
            /**
             * @hidden
             */
            static init(opts) {
                const entities = require("../../internal");
                const classProto = Class.prototype;
                prototypeChain.forEach((className, index) => {
                    const entity = entities[className];
                    /*
                     * NOTE @monitz87: This is the only way I managed to spoof "instanceof"
                     *  without breaking everything else:
                     *
                     * - If the Entity in question isn't being mocked as an import (entity.isMockEntity === false),
                     *   then we only have to set its prototype as the new Class's prototype and the entire chain is
                     *   reproduced
                     * - Otherwise, we only need to append the previous classes in the chain, since the mocked class is already an
                     *   instance of itself, and trying to set it as its own prototype results in an error
                     *
                     */
                    if (entity.isMockEntity) {
                        if (index === 0) {
                            Object.setPrototypeOf(classProto, entities.Entity.prototype);
                        }
                        else {
                            Object.setPrototypeOf(classProto, entities[prototypeChain[index - 1]].prototype);
                        }
                    }
                    else if (index === prototypeChain.length - 1) {
                        Object.setPrototypeOf(classProto, entity.prototype);
                    }
                });
                this.options = initialOptions(opts);
            }
            /**
             * @hidden
             */
            static setOptions(options) {
                this.options = this.mergeOptions(options);
            }
            /**
             * @hidden
             */
            static resetOptions() {
                this.options = initialOptions();
            }
            /**
             * @hidden
             */
            static getConstructorStub() {
                return this.constructorStub;
            }
            /**
             * @hidden
             */
            configure(opts) {
                const fullOpts = MockClass.mergeOptions(opts);
                super.configure(fullOpts);
                this.exists.returns(fullOpts.exists);
                this.isEqual.returns(fullOpts.isEqual);
                this.toJson.returns(fullOpts.toJson);
            }
        },
        _a.constructorStub = sinon_1.default.stub(),
        _a.options = {},
        _a.isMockEntity = true,
        _a;
}
/**
 * Make an entity getter stub that returns a value or calls a specific function
 */
function createEntityGetterStub(args, isAsync = true) {
    if (typeof args === 'function' && 'withArgs' in args) {
        return args;
    }
    const newStub = sinon_1.default.stub();
    if (typeof args === 'function') {
        newStub.callsFake(args);
    }
    else if (isAsync) {
        newStub.resolves(args);
    }
    else {
        newStub.returns(args);
    }
    return newStub;
}
const MockIdentityClass = createMockEntityClass(class {
    constructor() {
        this.portfolios = {};
        this.authorizations = {};
        this.assetPermissions = {};
    }
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['did']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'identity';
        this.did = opts.did;
        this.hasRoles = createEntityGetterStub(opts.hasRoles);
        this.checkRoles = createEntityGetterStub(opts.checkRoles);
        this.hasRole = createEntityGetterStub(opts.hasRole);
        this.hasValidCdd = createEntityGetterStub(opts.hasValidCdd);
        this.getPrimaryAccount = createEntityGetterStub(opts.getPrimaryAccount);
        this.authorizations.getReceived = createEntityGetterStub(opts.authorizationsGetReceived);
        this.authorizations.getSent = createEntityGetterStub(opts.authorizationsGetSent);
        this.assetPermissions.get = createEntityGetterStub(opts.assetPermissionsGet);
        this.assetPermissions.getGroup = createEntityGetterStub(opts.assetPermissionsGetGroup);
        this.assetPermissions.hasPermissions = createEntityGetterStub(opts.assetPermissionsHasPermissions);
        this.assetPermissions.checkPermissions = createEntityGetterStub(opts.assetPermissionsCheckPermissions);
        this.getVenues = createEntityGetterStub(opts.getVenues);
        this.getScopeId = createEntityGetterStub(opts.getScopeId);
        this.getAssetBalance = createEntityGetterStub(opts.getAssetBalance);
        this.getSecondaryAccounts = createEntityGetterStub(opts.getSecondaryAccounts);
        this.areSecondaryAccountsFrozen = createEntityGetterStub(opts.areSecondaryAccountsFrozen);
        this.isCddProvider = createEntityGetterStub(opts.isCddProvider);
    }
}, () => ({
    did: 'someDid',
    hasValidCdd: true,
    isCddProvider: false,
    authorizationsGetReceived: [],
    authorizationsGetSent: { data: [], next: null, count: new bignumber_js_1.default(0) },
    getVenues: [],
    getScopeId: 'someScopeId',
    getAssetBalance: new bignumber_js_1.default(100),
    getSecondaryAccounts: [],
    areSecondaryAccountsFrozen: false,
    getPrimaryAccount: {
        account: exports.getAccountInstance(),
        permissions: {
            assets: null,
            portfolios: null,
            transactions: null,
            transactionGroups: [],
        },
    },
    assetPermissionsGet: [],
    assetPermissionsGetGroup: exports.getKnownPermissionGroupInstance(),
    assetPermissionsCheckPermissions: {
        result: true,
    },
    assetPermissionsHasPermissions: true,
    hasRole: true,
    hasRoles: true,
    checkRoles: {
        result: true,
    },
    toJson: 'someDid',
}), ['Identity']);
const MockAccountClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['address']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'account';
        this.address = opts.address;
        this.key = opts.key;
        this.isFrozen = createEntityGetterStub(opts.isFrozen);
        this.getBalance = createEntityGetterStub(opts.getBalance);
        this.getIdentity = createEntityGetterStub(opts.getIdentity);
        this.getTransactionHistory = createEntityGetterStub(opts.getTransactionHistory);
        this.hasPermissions = createEntityGetterStub(opts.hasPermissions);
        this.checkPermissions = createEntityGetterStub(opts.checkPermissions);
    }
}, () => ({
    address: 'someAddress',
    key: 'someKey',
    getBalance: {
        free: new bignumber_js_1.default(100),
        locked: new bignumber_js_1.default(10),
        total: new bignumber_js_1.default(110),
    },
    getTransactionHistory: [],
    getIdentity: exports.getIdentityInstance(),
    isFrozen: false,
    hasPermissions: true,
    checkPermissions: {
        result: true,
    },
}), ['Account']);
const MockSubsidyClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['beneficiary', 'subsidizer']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'subsidy';
        this.beneficiary = exports.getAccountInstance({ address: opts.beneficiary });
        this.subsidizer = exports.getAccountInstance({ address: opts.subsidizer });
        this.getAllowance = createEntityGetterStub(opts.getAllowance);
    }
}, () => ({
    beneficiary: 'beneficiary',
    subsidizer: 'subsidizer',
    getAllowance: new bignumber_js_1.default(100),
    toJson: {
        beneficiary: 'beneficiary',
        subsidizer: 'subsidizer',
    },
}), ['Subsidy']);
const MockTickerReservationClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['ticker']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'tickerReservation';
        this.ticker = opts.ticker;
        this.details = createEntityGetterStub(opts.details);
    }
}, () => ({
    ticker: 'SOME_TICKER',
    details: {
        owner: exports.getIdentityInstance(),
        expiryDate: new Date(),
        status: types_1.TickerReservationStatus.Reserved,
    },
}), ['TickerReservation']);
const MockAssetClass = createMockEntityClass(class {
    constructor() {
        this.transfers = {};
        this.transferRestrictions = {
            count: {},
            percentage: {},
        };
        this.corporateActions = {};
        this.permissions = {};
        this.compliance = {
            requirements: {},
        };
        this.checkpoints = {
            schedules: {},
        };
    }
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['ticker']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'asset';
        this.ticker = opts.ticker;
        this.details = createEntityGetterStub(opts.details);
        this.currentFundingRound = createEntityGetterStub(opts.currentFundingRound);
        this.isFrozen = createEntityGetterStub(opts.isFrozen);
        this.transfers.canTransfer = createEntityGetterStub(opts.transfersCanTransfer);
        this.getIdentifiers = createEntityGetterStub(opts.getIdentifiers);
        this.transferRestrictions.count.get = createEntityGetterStub(opts.transferRestrictionsCountGet);
        this.transferRestrictions.percentage.get = createEntityGetterStub(opts.transferRestrictionsPercentageGet);
        this.corporateActions.getAgents = createEntityGetterStub(opts.corporateActionsGetAgents);
        this.corporateActions.getDefaultConfig = createEntityGetterStub(opts.corporateActionsGetDefaultConfig);
        this.permissions.getGroups = createEntityGetterStub(opts.permissionsGetGroups);
        this.permissions.getAgents = createEntityGetterStub(opts.permissionsGetAgents);
        this.compliance.requirements.get = createEntityGetterStub(opts.complianceRequirementsGet);
        this.checkpoints.schedules.getOne = createEntityGetterStub(opts.checkpointsSchedulesGetOne);
        this.checkpoints.getOne = createEntityGetterStub(opts.checkpointsGetOne);
    }
}, () => ({
    ticker: 'SOME_TICKER',
    did: 'assetDid',
    details: {
        owner: exports.getIdentityInstance(),
        name: 'ASSET_NAME',
        totalSupply: new bignumber_js_1.default(1000000),
        isDivisible: false,
        primaryIssuanceAgents: [],
        fullAgents: [],
        assetType: types_1.KnownAssetType.EquityCommon,
        requiresInvestorUniqueness: false,
    },
    currentFundingRound: 'Series A',
    isFrozen: false,
    transfersCanTransfer: types_1.TransferStatus.Success,
    getIdentifiers: [],
    transferRestrictionsCountGet: {
        restrictions: [],
        availableSlots: new bignumber_js_1.default(3),
    },
    transferRestrictionsPercentageGet: {
        restrictions: [],
        availableSlots: new bignumber_js_1.default(3),
    },
    corporateActionsGetAgents: [],
    corporateActionsGetDefaultConfig: {
        targets: { identities: [], treatment: types_1.TargetTreatment.Exclude },
        defaultTaxWithholding: new bignumber_js_1.default(10),
        taxWithholdings: [],
    },
    permissionsGetAgents: [],
    permissionsGetGroups: {
        known: [],
        custom: [],
    },
    complianceRequirementsGet: {
        requirements: [],
        defaultTrustedClaimIssuers: [],
    },
    checkpointsGetOne: exports.getCheckpointInstance(),
    checkpointsSchedulesGetOne: {
        schedule: exports.getCheckpointScheduleInstance(),
        details: {
            remainingCheckpoints: new bignumber_js_1.default(3),
            nextCheckpointDate: new Date(new Date().getTime() + 1000 * 60 * 60),
        },
    },
    toJson: 'SOME_TICKER',
}), ['Asset']);
const MockAuthorizationRequestClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['authId', 'target', 'issuer', 'expiry', 'data']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'authorizationRequest';
        this.authId = opts.authId;
        this.issuer = opts.issuer;
        this.target = opts.target;
        this.expiry = opts.expiry;
        this.data = opts.data;
        this.isExpired = createEntityGetterStub(opts.isExpired, false);
    }
}, () => ({
    authId: new bignumber_js_1.default(1),
    isExpired: false,
    target: exports.getIdentityInstance({ did: 'targetDid' }),
    issuer: exports.getIdentityInstance({ did: 'issuerDid' }),
    data: { type: types_1.AuthorizationType.TransferAssetOwnership, value: 'UNWANTED_TOKEN' },
    expiry: null,
}), ['AuthorizationRequest']);
const MockVenueClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['id']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'venue';
        this.id = opts.id;
        this.details = createEntityGetterStub(opts.details);
    }
}, () => ({
    id: new bignumber_js_1.default(1),
    details: {
        owner: exports.getIdentityInstance(),
        type: types_1.VenueType.Distribution,
        description: 'someDescription',
    },
}), ['Venue']);
const MockInstructionClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['id']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'instruction';
        this.id = opts.id;
        this.details = createEntityGetterStub(opts.details);
        this.getLegs = createEntityGetterStub(opts.getLegs);
        this.isPending = createEntityGetterStub(opts.isPending);
    }
}, () => ({
    id: new bignumber_js_1.default(1),
    details: {
        status: types_1.InstructionStatus.Pending,
        createdAt: new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000),
        tradeDate: null,
        valueDate: null,
        venue: exports.getVenueInstance(),
        type: types_1.InstructionType.SettleOnAffirmation,
    },
    getLegs: {
        data: [
            {
                from: exports.getNumberedPortfolioInstance({ did: 'someDid', id: new bignumber_js_1.default(1) }),
                to: exports.getNumberedPortfolioInstance({ did: 'otherDid', id: new bignumber_js_1.default(1) }),
                asset: exports.getAssetInstance(),
                amount: new bignumber_js_1.default(100),
            },
        ],
        next: null,
    },
    isPending: false,
}), ['Instruction']);
const MockNumberedPortfolioClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['id', 'did']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'numberedPortfolio';
        this.id = opts.id;
        this.owner = exports.getIdentityInstance({ did: opts.did });
        this.isOwnedBy = createEntityGetterStub(opts.isOwnedBy);
        this.getAssetBalances = createEntityGetterStub(opts.getAssetBalances);
        this.getCustodian = createEntityGetterStub(opts.getCustodian);
        this.isCustodiedBy = createEntityGetterStub(opts.isCustodiedBy);
    }
}, () => ({
    id: new bignumber_js_1.default(1),
    isOwnedBy: true,
    getAssetBalances: [
        {
            asset: exports.getAssetInstance(),
            total: new bignumber_js_1.default(1),
            locked: new bignumber_js_1.default(0),
            free: new bignumber_js_1.default(1),
        },
    ],
    did: 'someDid',
    getCustodian: exports.getIdentityInstance(),
    isCustodiedBy: true,
    toJson: {
        did: 'someDid',
        id: '1',
    },
}), ['Portfolio', 'NumberedPortfolio']);
const MockDefaultPortfolioClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['did']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'defaultPortfolio';
        this.owner = exports.getIdentityInstance({ did: opts.did });
        this.isOwnedBy = createEntityGetterStub(opts.isOwnedBy);
        this.getAssetBalances = createEntityGetterStub(opts.getAssetBalances);
        this.getCustodian = createEntityGetterStub(opts.getCustodian);
        this.isCustodiedBy = createEntityGetterStub(opts.isCustodiedBy);
    }
}, () => ({
    isOwnedBy: true,
    getAssetBalances: [
        {
            asset: exports.getAssetInstance(),
            total: new bignumber_js_1.default(1),
            locked: new bignumber_js_1.default(0),
            free: new bignumber_js_1.default(1),
        },
    ],
    did: 'someDid',
    getCustodian: exports.getIdentityInstance(),
    isCustodiedBy: true,
    toJson: {
        did: 'someDid',
    },
}), ['Portfolio', 'DefaultPortfolio']);
const MockOfferingClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['id', 'ticker']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'sto';
        this.id = opts.id;
        this.asset = exports.getAssetInstance({ ticker: opts.ticker });
        this.details = createEntityGetterStub(opts.details);
    }
}, () => ({
    details: {
        creator: exports.getIdentityInstance(),
        venue: exports.getVenueInstance(),
        name: 'MyOffering',
        offeringPortfolio: exports.getNumberedPortfolioInstance({ did: 'offeringDid', id: new bignumber_js_1.default(1) }),
        raisingPortfolio: exports.getNumberedPortfolioInstance({ did: 'offeringDid', id: new bignumber_js_1.default(2) }),
        end: null,
        start: new Date('10/14/1987'),
        status: {
            timing: types_1.OfferingTimingStatus.Started,
            balance: types_1.OfferingBalanceStatus.Available,
            sale: types_1.OfferingSaleStatus.Live,
        },
        tiers: [
            {
                price: new bignumber_js_1.default(100000000),
                remaining: new bignumber_js_1.default(700000000),
                amount: new bignumber_js_1.default(1000000000),
            },
        ],
        totalAmount: new bignumber_js_1.default(1000000000),
        totalRemaining: new bignumber_js_1.default(700000000),
        raisingCurrency: 'USD',
        minInvestment: new bignumber_js_1.default(100000000),
    },
    ticker: 'SOME_TICKER',
    id: new bignumber_js_1.default(1),
}), ['Offering']);
const MockCheckpointClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['id', 'ticker']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'checkpoint';
        this.id = opts.id;
        this.asset = exports.getAssetInstance({ ticker: opts.ticker });
        this.createdAt = createEntityGetterStub(opts.createdAt);
        this.totalSupply = createEntityGetterStub(opts.totalSupply);
        this.allBalances = createEntityGetterStub(opts.allBalances);
        this.balance = createEntityGetterStub(opts.balance);
    }
}, () => ({
    totalSupply: new bignumber_js_1.default(10000),
    createdAt: new Date('10/14/1987'),
    ticker: 'SOME_TICKER',
    id: new bignumber_js_1.default(1),
    balance: new bignumber_js_1.default(1000),
    allBalances: {
        data: [
            {
                identity: exports.getIdentityInstance(),
                balance: new bignumber_js_1.default(1000),
            },
        ],
        next: null,
    },
}), ['Checkpoint']);
const MockCheckpointScheduleClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['id', 'ticker', 'start', 'period']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'checkpointSchedule';
        this.id = opts.id;
        this.asset = exports.getAssetInstance({ ticker: opts.ticker });
        this.start = opts.start;
        this.period = opts.period;
        this.expiryDate = opts.expiryDate;
        this.complexity = opts.complexity;
        this.details = createEntityGetterStub(opts.details);
    }
}, () => ({
    id: new bignumber_js_1.default(1),
    ticker: 'SOME_TICKER',
    start: new Date(new Date().getTime() + 24 * 60 * 60 * 1000),
    period: {
        unit: types_1.CalendarUnit.Month,
        amount: new bignumber_js_1.default(1),
    },
    expiryDate: new Date(new Date().getTime() + 60 * 24 * 60 * 60 * 1000),
    complexity: new bignumber_js_1.default(2),
    details: {
        remainingCheckpoints: new bignumber_js_1.default(1),
        nextCheckpointDate: new Date('10/10/2030'),
    },
}), ['CheckpointSchedule']);
const MockCorporateActionClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, [
            'id',
            'ticker',
            'kind',
            'declarationDate',
            'targets',
            'description',
            'defaultTaxWithholding',
            'taxWithholdings',
        ]);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'corporateAction';
        this.id = opts.id;
        this.asset = exports.getAssetInstance({ ticker: opts.ticker });
        this.kind = opts.kind;
        this.declarationDate = opts.declarationDate;
        this.description = opts.description;
        this.targets = opts.targets;
        this.defaultTaxWithholding = opts.defaultTaxWithholding;
        this.taxWithholdings = opts.taxWithholdings;
    }
}, () => ({
    id: new bignumber_js_1.default(1),
    ticker: 'SOME_TICKER',
    kind: types_1.CorporateActionKind.UnpredictableBenefit,
    declarationDate: new Date('10/14/1987'),
    description: 'someDescription',
    targets: {
        identities: [exports.getIdentityInstance()],
        treatment: types_1.TargetTreatment.Include,
    },
    defaultTaxWithholding: new bignumber_js_1.default(10),
    taxWithholdings: [
        {
            identity: exports.getIdentityInstance(),
            percentage: new bignumber_js_1.default(40),
        },
    ],
}), ['CorporateActionBase', 'CorporateAction']);
const MockDividendDistributionClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, [
            'id',
            'ticker',
            'declarationDate',
            'targets',
            'kind',
            'description',
            'defaultTaxWithholding',
            'taxWithholdings',
            'origin',
            'currency',
            'perShare',
            'maxAmount',
            'expiryDate',
            'paymentDate',
        ]);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'dividendDistribution';
        this.id = opts.id;
        this.asset = exports.getAssetInstance({ ticker: opts.ticker });
        this.kind = opts.kind;
        this.origin = opts.origin;
        this.declarationDate = opts.declarationDate;
        this.description = opts.description;
        this.targets = opts.targets;
        this.defaultTaxWithholding = opts.defaultTaxWithholding;
        this.taxWithholdings = opts.taxWithholdings;
        this.currency = opts.currency;
        this.perShare = opts.perShare;
        this.maxAmount = opts.maxAmount;
        this.expiryDate = opts.expiryDate;
        this.paymentDate = opts.paymentDate;
        this.details = createEntityGetterStub(opts.details);
        this.getParticipant = createEntityGetterStub(opts.getParticipant);
        this.checkpoint = createEntityGetterStub(opts.checkpoint);
    }
}, () => ({
    id: new bignumber_js_1.default(1),
    ticker: 'SOME_TICKER',
    kind: types_1.CorporateActionKind.UnpredictableBenefit,
    origin: exports.getDefaultPortfolioInstance(),
    declarationDate: new Date('10/14/1987'),
    description: 'someDescription',
    targets: {
        identities: [exports.getIdentityInstance()],
        treatment: types_1.TargetTreatment.Include,
    },
    defaultTaxWithholding: new bignumber_js_1.default(10),
    taxWithholdings: [
        {
            identity: exports.getIdentityInstance(),
            percentage: new bignumber_js_1.default(40),
        },
    ],
    currency: 'USD',
    perShare: new bignumber_js_1.default(100),
    maxAmount: new bignumber_js_1.default(1000000),
    expiryDate: null,
    paymentDate: new Date(new Date().getTime() + 60 * 24 * 60 * 60 * 1000),
    details: {
        remainingFunds: new bignumber_js_1.default(100),
        fundsReclaimed: false,
    },
    getParticipant: {
        identity: exports.getIdentityInstance(),
        amount: new bignumber_js_1.default(100),
        paid: false,
    },
    checkpoint: exports.getCheckpointInstance(),
}), ['CorporateActionBase', 'DividendDistribution']);
const MockCustomPermissionGroupClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['id', 'ticker']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'customPermissionGroup';
        this.id = opts.id;
        this.asset = exports.getAssetInstance({ ticker: opts.ticker });
        this.getPermissions = createEntityGetterStub(opts.getPermissions);
    }
}, () => ({
    ticker: 'SOME_TICKER',
    id: new bignumber_js_1.default(1),
    getPermissions: {
        transactions: null,
        transactionGroups: [],
    },
}), ['PermissionGroup', 'CustomPermissionGroup']);
const MockKnownPermissionGroupClass = createMockEntityClass(class {
    /**
     * @hidden
     */
    argsToOpts(...args) {
        return extractFromArgs(args, ['type', 'ticker']);
    }
    /**
     * @hidden
     */
    configure(opts) {
        this.uuid = 'knownPermissionGroup';
        this.type = opts.type;
        this.asset = exports.getAssetInstance({ ticker: opts.ticker });
        this.getPermissions = createEntityGetterStub(opts.getPermissions);
    }
}, () => ({
    ticker: 'SOME_TICKER',
    type: types_1.PermissionGroupType.Full,
    getPermissions: {
        transactions: null,
        transactionGroups: [],
    },
}), ['PermissionGroup', 'KnownPermissionGroup']);
const mockIdentityModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { Identity: MockIdentityClass }));
exports.mockIdentityModule = mockIdentityModule;
const mockAccountModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { Account: MockAccountClass }));
exports.mockAccountModule = mockAccountModule;
const mockSubsidyModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { Subsidy: MockSubsidyClass }));
exports.mockSubsidyModule = mockSubsidyModule;
const mockTickerReservationModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { TickerReservation: MockTickerReservationClass }));
exports.mockTickerReservationModule = mockTickerReservationModule;
const mockAssetModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { Asset: MockAssetClass }));
exports.mockAssetModule = mockAssetModule;
const mockAuthorizationRequestModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { AuthorizationRequest: MockAuthorizationRequestClass }));
exports.mockAuthorizationRequestModule = mockAuthorizationRequestModule;
const mockVenueModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { Venue: MockVenueClass }));
exports.mockVenueModule = mockVenueModule;
const mockInstructionModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { Instruction: MockInstructionClass }));
exports.mockInstructionModule = mockInstructionModule;
const mockNumberedPortfolioModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { NumberedPortfolio: MockNumberedPortfolioClass }));
exports.mockNumberedPortfolioModule = mockNumberedPortfolioModule;
const mockDefaultPortfolioModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { DefaultPortfolio: MockDefaultPortfolioClass }));
exports.mockDefaultPortfolioModule = mockDefaultPortfolioModule;
const mockOfferingModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { Offering: MockOfferingClass }));
exports.mockOfferingModule = mockOfferingModule;
const mockCheckpointModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { Checkpoint: MockCheckpointClass }));
exports.mockCheckpointModule = mockCheckpointModule;
const mockCheckpointScheduleModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { CheckpointSchedule: MockCheckpointScheduleClass }));
exports.mockCheckpointScheduleModule = mockCheckpointScheduleModule;
const mockCorporateActionModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { CorporateAction: MockCorporateActionClass }));
exports.mockCorporateActionModule = mockCorporateActionModule;
const mockDividendDistributionModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { DividendDistribution: MockDividendDistributionClass }));
exports.mockDividendDistributionModule = mockDividendDistributionModule;
const mockCustomPermissionGroupModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { CustomPermissionGroup: MockCustomPermissionGroupClass }));
exports.mockCustomPermissionGroupModule = mockCustomPermissionGroupModule;
const mockKnownPermissionGroupModule = (path) => () => (Object.assign(Object.assign({}, jest.requireActual(path)), { KnownPermissionGroup: MockKnownPermissionGroupClass }));
exports.mockKnownPermissionGroupModule = mockKnownPermissionGroupModule;
/**
 * @hidden
 *
 * Initialize mock classes with the default configuration
 */
const initMocks = function (opts) {
    MockIdentityClass.init(opts === null || opts === void 0 ? void 0 : opts.identityOptions);
    MockAccountClass.init(opts === null || opts === void 0 ? void 0 : opts.accountOptions);
    MockSubsidyClass.init(opts === null || opts === void 0 ? void 0 : opts.subsidyOptions);
    MockTickerReservationClass.init(opts === null || opts === void 0 ? void 0 : opts.tickerReservationOptions);
    MockAssetClass.init(opts === null || opts === void 0 ? void 0 : opts.assetOptions);
    MockAuthorizationRequestClass.init(opts === null || opts === void 0 ? void 0 : opts.authorizationRequestOptions);
    MockVenueClass.init(opts === null || opts === void 0 ? void 0 : opts.venueOptions);
    MockInstructionClass.init(opts === null || opts === void 0 ? void 0 : opts.instructionOptions);
    MockNumberedPortfolioClass.init(opts === null || opts === void 0 ? void 0 : opts.numberedPortfolioOptions);
    MockDefaultPortfolioClass.init(opts === null || opts === void 0 ? void 0 : opts.defaultPortfolioOptions);
    MockCustomPermissionGroupClass.init(opts === null || opts === void 0 ? void 0 : opts.customPermissionGroupOptions);
    MockKnownPermissionGroupClass.init(opts === null || opts === void 0 ? void 0 : opts.knownPermissionGroupOptions);
    MockOfferingClass.init(opts === null || opts === void 0 ? void 0 : opts.offeringOptions);
    MockCheckpointClass.init(opts === null || opts === void 0 ? void 0 : opts.checkpointOptions);
    MockCheckpointScheduleClass.init(opts === null || opts === void 0 ? void 0 : opts.checkpointScheduleOptions);
    MockCorporateActionClass.init(opts === null || opts === void 0 ? void 0 : opts.corporateActionOptions);
    MockDividendDistributionClass.init(opts === null || opts === void 0 ? void 0 : opts.dividendDistributionOptions);
};
exports.initMocks = initMocks;
/**
 * @hidden
 *s
 * Configure mock classes (calling .reset will go back to the default configuration)
 */
const configureMocks = function (opts) {
    MockIdentityClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.identityOptions);
    MockAccountClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.accountOptions);
    MockSubsidyClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.subsidyOptions);
    MockTickerReservationClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.tickerReservationOptions);
    MockAssetClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.assetOptions);
    MockAuthorizationRequestClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.authorizationRequestOptions);
    MockVenueClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.venueOptions);
    MockInstructionClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.instructionOptions);
    MockNumberedPortfolioClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.numberedPortfolioOptions);
    MockDefaultPortfolioClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.defaultPortfolioOptions);
    MockCustomPermissionGroupClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.customPermissionGroupOptions);
    MockKnownPermissionGroupClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.knownPermissionGroupOptions);
    MockOfferingClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.offeringOptions);
    MockCheckpointClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.checkpointOptions);
    MockCheckpointScheduleClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.checkpointScheduleOptions);
    MockCorporateActionClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.corporateActionOptions);
    MockDividendDistributionClass.setOptions(opts === null || opts === void 0 ? void 0 : opts.dividendDistributionOptions);
};
exports.configureMocks = configureMocks;
/**
 * @hidden
 * Reset all mock classes to their default values
 */
const reset = function () {
    MockIdentityClass.resetOptions();
    MockAccountClass.resetOptions();
    MockSubsidyClass.resetOptions();
    MockTickerReservationClass.resetOptions();
    MockAssetClass.resetOptions();
    MockAuthorizationRequestClass.resetOptions();
    MockVenueClass.resetOptions();
    MockInstructionClass.resetOptions();
    MockNumberedPortfolioClass.resetOptions();
    MockDefaultPortfolioClass.resetOptions();
    MockCustomPermissionGroupClass.resetOptions();
    MockKnownPermissionGroupClass.resetOptions();
    MockOfferingClass.resetOptions();
    MockCheckpointClass.resetOptions();
    MockCheckpointScheduleClass.resetOptions();
    MockCorporateActionClass.resetOptions();
    MockDividendDistributionClass.resetOptions();
};
exports.reset = reset;
/**
 * @hidden
 * Retrieve an Identity instance
 */
const getIdentityInstance = (opts) => {
    const instance = new MockIdentityClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getIdentityInstance = getIdentityInstance;
/**
 * @hidden
 * Retrieve an Account instance
 */
const getAccountInstance = (opts) => {
    const instance = new MockAccountClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getAccountInstance = getAccountInstance;
/**
 * @hidden
 * Retrieve an Subsidy instance
 */
const getSubsidyInstance = (opts) => {
    const instance = new MockSubsidyClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getSubsidyInstance = getSubsidyInstance;
/**
 * @hidden
 * Retrieve a TickerReservation instance
 */
const getTickerReservationInstance = (opts) => {
    const instance = new MockTickerReservationClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getTickerReservationInstance = getTickerReservationInstance;
/**
 * @hidden
 * Retrieve a Asset instance
 */
const getAssetInstance = (opts) => {
    const instance = new MockAssetClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getAssetInstance = getAssetInstance;
/**
 * @hidden
 * Retrieve an AuthorizationRequest instance
 */
const getAuthorizationRequestInstance = (opts) => {
    const instance = new MockAuthorizationRequestClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getAuthorizationRequestInstance = getAuthorizationRequestInstance;
/**
 * @hidden
 * Retrieve a Venue instance
 */
const getVenueInstance = (opts) => {
    const instance = new MockVenueClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getVenueInstance = getVenueInstance;
/**
 * @hidden
 * Retrieve a NumberedPortfolio instance
 */
const getNumberedPortfolioInstance = (opts) => {
    const instance = new MockNumberedPortfolioClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getNumberedPortfolioInstance = getNumberedPortfolioInstance;
/**
 * @hidden
 * Retrieve a DefaultPortfolio instance
 */
const getDefaultPortfolioInstance = (opts) => {
    const instance = new MockDefaultPortfolioClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getDefaultPortfolioInstance = getDefaultPortfolioInstance;
/**
 * @hidden
 * Retrieve a CustomPermissionGroup instance
 */
const getCustomPermissionGroupInstance = (opts) => {
    const instance = new MockCustomPermissionGroupClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getCustomPermissionGroupInstance = getCustomPermissionGroupInstance;
/**
 * @hidden
 * Retrieve a KnownPermissionGroup instance
 */
const getKnownPermissionGroupInstance = (opts) => {
    const instance = new MockKnownPermissionGroupClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getKnownPermissionGroupInstance = getKnownPermissionGroupInstance;
/**
 * @hidden
 * Retrieve an Instruction instance
 */
const getInstructionInstance = (opts) => {
    const instance = new MockInstructionClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getInstructionInstance = getInstructionInstance;
/**
 * @hidden
 * Retrieve an Offering instance
 */
const getOfferingInstance = (opts) => {
    const instance = new MockOfferingClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getOfferingInstance = getOfferingInstance;
/**
 * @hidden
 * Retrieve a Checkpoint instance
 */
const getCheckpointInstance = (opts) => {
    const instance = new MockCheckpointClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getCheckpointInstance = getCheckpointInstance;
/**
 * @hidden
 * Retrieve a CheckpointSchedule instance
 */
const getCheckpointScheduleInstance = (opts) => {
    const instance = new MockCheckpointScheduleClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getCheckpointScheduleInstance = getCheckpointScheduleInstance;
/**
 * @hidden
 * Retrieve a CorporateAction instance
 */
const getCorporateActionInstance = (opts) => {
    const instance = new MockCorporateActionClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getCorporateActionInstance = getCorporateActionInstance;
/**
 * @hidden
 * Retrieve a DividendDistribution instance
 */
const getDividendDistributionInstance = (opts) => {
    const instance = new MockDividendDistributionClass();
    if (opts) {
        instance.configure(opts);
    }
    return instance;
};
exports.getDividendDistributionInstance = getDividendDistributionInstance;
//# sourceMappingURL=entities.js.map