var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { ResultCode } from '@iotize/tap/client/api';
import { Tap } from './tap';
/**
 * If response status code is NOT_IMPLEMENTED or NOT_FOUND it will returns the default value
 * @param responsePromise
 * @param defaultValue
 */
export function defaultValueIfTapRequetNotImplemented(responsePromise, defaultValue) {
    return __awaiter(this, void 0, void 0, function* () {
        const response = yield responsePromise;
        if (!response.isSuccessful()) {
            if (response.status === ResultCode.NOT_IMPLEMENTED ||
                response.status === ResultCode.NOT_FOUND) {
                return defaultValue;
            }
        }
        return response.body();
    });
}
/**
 * Utility function add a new getter to the Tap prototype
 */
export function defineTapPropertyExtension(propName, factory) {
    Object.defineProperty(Tap.prototype, propName, {
        get() {
            const that = this;
            const hiddentPropName = `__${propName}__`;
            if (!that[hiddentPropName]) {
                that[hiddentPropName] = factory({
                    tap: this,
                });
            }
            return that[hiddentPropName];
        },
        enumerable: false,
        configurable: true,
    });
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwLWhlbHBlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9saWIvdGFwLWhlbHBlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFHcEQsT0FBTyxFQUFFLEdBQUcsRUFBRSxNQUFNLE9BQU8sQ0FBQztBQUU1Qjs7Ozt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