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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwLWhlbHBlci5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0Bpb3RpemUvdGFwLyIsInNvdXJjZXMiOlsibGliL3RhcC1oZWxwZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBR3BELE9BQU8sRUFBRSxHQUFHLEVBQUUsTUFBTSxPQUFPLENBQUM7QUFFNUI7Ozs7R0FJRztBQU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