import { RemoteMethodLoader } from '@rxap/remote-method';

class RemoteMethodTestingLoader extends RemoteMethodLoader {
    constructor() {
        super(...arguments);
        this.mockedRemoteMethods = new Map();
    }
    mock(remoteMethodId, resultOrFunction) {
        let resultFunction;
        if (typeof resultOrFunction !== 'function') {
            resultFunction = () => resultOrFunction;
        }
        else {
            resultFunction = resultOrFunction;
        }
        this.mockedRemoteMethods.set(remoteMethodId, resultFunction);
    }
    clearMocks() {
        this.mockedRemoteMethods.clear();
    }
    deleteMock(remoteMethodId) {
        return this.mockedRemoteMethods.delete(remoteMethodId);
    }
    hasMock(remoteMethodId) {
        return this.mockedRemoteMethods.has(remoteMethodId);
    }
    getMock(remoteMethodId) {
        if (!this.hasMock(remoteMethodId)) {
            throw new Error(`A remote method mock with the id '${remoteMethodId}' is not registered`);
        }
        return this.mockedRemoteMethods.get(remoteMethodId);
    }
    async call$(remoteMethodOrIdOrToken, parameters, metadata) {
        if (typeof remoteMethodOrIdOrToken === 'string') {
            if (this.hasMock(remoteMethodOrIdOrToken)) {
                const resultFunction = this.getMock(remoteMethodOrIdOrToken);
                return await resultFunction(parameters, metadata);
            }
            return super.call$(remoteMethodOrIdOrToken, parameters, metadata);
        }
        return super.call$(remoteMethodOrIdOrToken, parameters, metadata);
    }
}
const REMOTE_METHOD_TESTING_LOADER_PROVIDER = {
    provide: RemoteMethodLoader,
    useClass: RemoteMethodTestingLoader,
};

// region 
// endregion

/**
 * Generated bundle index. Do not edit.
 */

export { REMOTE_METHOD_TESTING_LOADER_PROVIDER, RemoteMethodTestingLoader };
//# sourceMappingURL=rxap-remote-method-testing.mjs.map
