001/* 002 * Copyright 2026 Revetware LLC. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.revetsec.scim; 018 019import static java.util.Objects.requireNonNull; 020 021import com.google.errorprone.annotations.CheckReturnValue; 022import org.jspecify.annotations.NonNull; 023 024import javax.annotation.concurrent.Immutable; 025 026/** Conservative membership reduction, full-evaluation fallback, or a fixed rejection. 027 * @since 1.0.0 028 */ 029@Immutable 030public sealed interface ScimMembershipPatchResult permits ScimMembershipPatchResult.Reduced, 031 ScimMembershipPatchResult.RequiresFullEvaluation, ScimMembershipPatchResult.Rejected { 032 /** Ordered ID instructions; success does not establish modification or authorization. 033 * @since 1.0.0 034 */ 035 @Immutable 036 final class Reduced implements ScimMembershipPatchResult { 037 private final @NonNull ScimMembershipPatch membershipPatch; 038 Reduced(@NonNull ScimMembershipPatch membershipPatch) { this.membershipPatch = requireNonNull(membershipPatch); } 039 040 /** Returns the ordered membership instructions and remaining operations. 041 * @return membership patch 042 * @since 1.0.0 043 */ 044 @CheckReturnValue public @NonNull ScimMembershipPatch getMembershipPatch() { return membershipPatch; } 045 046 /** Returns a fixed redacted diagnostic. 047 * @return redacted description 048 * @since 1.0.0 049 */ 050 @Override public @NonNull String toString() { return "ScimMembershipPatchResult.Reduced{<redacted>}"; } 051 } 052 053 /** Valid operations whose semantics cannot be represented as the conservative ID-only instructions. 054 * @since 1.0.0 055 */ 056 @Immutable 057 final class RequiresFullEvaluation implements ScimMembershipPatchResult { 058 static final @NonNull RequiresFullEvaluation INSTANCE = new RequiresFullEvaluation(); 059 private RequiresFullEvaluation() {} 060 061 /** Returns a fixed redacted diagnostic. 062 * @return redacted description 063 * @since 1.0.0 064 */ 065 @Override public @NonNull String toString() { return "ScimMembershipPatchResult.RequiresFullEvaluation"; } 066 } 067 068 /** A fixed error without partial executable instructions. 069 * @since 1.0.0 070 */ 071 @Immutable 072 final class Rejected implements ScimMembershipPatchResult { 073 private final @NonNull ScimError error; 074 Rejected(@NonNull ScimError error) { this.error = requireNonNull(error); } 075 076 /** Returns the fixed error. 077 * @return fixed error 078 * @since 1.0.0 079 */ 080 @CheckReturnValue public @NonNull ScimError getError() { return error; } 081 082 /** Returns a fixed redacted diagnostic. 083 * @return redacted description 084 * @since 1.0.0 085 */ 086 @Override public @NonNull String toString() { return "ScimMembershipPatchResult.Rejected{<redacted>}"; } 087 } 088}