"use strict";
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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShareResultFailure = exports.ShareResultSuccess = void 0;
/**
 * Represents the result of a successful share operation.
 */
class ShareResultSuccess {
    /**
     * @param updatedEntity The entity with updated encrypted metadata.
     */
    constructor(updatedEntity) {
        this.updatedEntity = updatedEntity;
    }
    get updatedEntityOrThrow() {
        return this.updatedEntity;
    }
    mapSuccess(f) {
        return new ShareResultSuccess(f(this.updatedEntity));
    }
    mapSuccessAsync(f) {
        return __awaiter(this, void 0, void 0, function* () {
            return new ShareResultSuccess(yield f(this.updatedEntity));
        });
    }
}
exports.ShareResultSuccess = ShareResultSuccess;
/**
 * Represents the result of a failed share operation.
 */
class ShareResultFailure {
    /**
     * @param errorsDetails Details of the errors, as returned by the server.
     * @param message Human-friendly error message, should provide additional context that the server may not have had, for example if the original user
     * request was modified by the crypto API for migration purposes.
     */
    constructor(errorsDetails, message) {
        this.errorsDetails = errorsDetails;
        this.message = message;
    }
    get updatedEntityOrThrow() {
        console.error(`Error when sharing an entity. Details: ${JSON.stringify(this.errorsDetails)}`);
        throw new Error(this.message);
    }
    mapSuccess(f) {
        return this;
    }
    mapSuccessAsync(f) {
        return Promise.resolve(this);
    }
}
exports.ShareResultFailure = ShareResultFailure;
//# sourceMappingURL=ShareResult.js.map