var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spread = (this && this.__spread) || function () {
    for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
    return ar;
};
import { TapResponse, ServiceCallRunner } from '@iotize/tap';
import { ResultCode } from '@iotize/tap/client/api';
import { TapResponseFrameBuilder } from '@iotize/tap/client/impl';
import { of } from 'rxjs';
import { delay } from 'rxjs/operators';
import { MockClient } from './mock-client';
export function createMockServiceFunctionCustom(responseBuilder, options) {
    if (options === void 0) { options = {
        responseDelay: 10
    }; }
    return function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        return of(responseBuilder.apply(void 0, __spread(args)))
            .pipe(delay(options.responseDelay))
            .toPromise();
    };
}
export function createMockServiceFunction(responseStatus, options) {
    if (responseStatus === void 0) { responseStatus = ResultCode.OK; }
    if (options === void 0) { options = {
        responseDelay: 10
    }; }
    return function () {
        var response = createMockServiceResponse(responseStatus);
        return of(response)
            .pipe(delay(options.responseDelay))
            .toPromise();
    };
}
export function createMockServiceFunctionWithBody(responseStatus, body, options) {
    if (responseStatus === void 0) { responseStatus = ResultCode.OK; }
    if (options === void 0) { options = {
        responseDelay: 10
    }; }
    return function () {
        var response = createMockServiceResponseWithBody(responseStatus, body);
        return of(response)
            .pipe(delay(options.responseDelay))
            .toPromise();
    };
}
export function createMockServiceResponse(responseStatus) {
    if (responseStatus === void 0) { responseStatus = ResultCode.OK; }
    var response = new TapResponse(TapResponseFrameBuilder.create(responseStatus));
    return response;
}
export function createMockServiceResponseWithBody(responseStatus, body) {
    if (responseStatus === void 0) { responseStatus = ResultCode.OK; }
    var response = new TapResponse(TapResponseFrameBuilder.create(responseStatus));
    if (body instanceof Uint8Array) {
        response['_tapResponse'].data = body;
    }
    if (body) {
        response.setBody(body);
    }
    return response;
}
export function createMockServiceResponseError(code) {
    var response = new TapResponse(TapResponseFrameBuilder.ERROR(code));
    return response;
}
export function createMockService(constructorFct) {
    var serviceCallRunnner = new MockServiceCallRunner();
    return new constructorFct(serviceCallRunnner);
}
var MockServiceCallRunner = /** @class */ (function (_super) {
    __extends(MockServiceCallRunner, _super);
    // TODO
    function MockServiceCallRunner() {
        return _super.call(this, new MockClient()) || this;
    }
    return MockServiceCallRunner;
}(ServiceCallRunner));
export { MockServiceCallRunner };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9jay1zZXJ2aWNlLXV0aWxpdHkuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9AaW90aXplL3RhcC90ZXN0aW5nLyIsInNvdXJjZXMiOlsibW9jay9tb2NrLXNlcnZpY2UtdXRpbGl0eS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQSxPQUFPLEVBQUUsV0FBVyxFQUFFLGlCQUFpQixFQUFFLE1BQU0sYUFBYSxDQUFDO0FBQzdELE9BQU8sRUFBRSxVQUFVLEVBQW9CLE1BQU0sd0JBQXdCLENBQUM7QUFDdEUsT0FBTyxFQUFFLHVCQUF1QixFQUFFLE1BQ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