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 com.google.errorprone.annotations.CheckReturnValue;
020import org.jspecify.annotations.NonNull;
021import javax.annotation.concurrent.Immutable;
022import java.util.Set;
023import static java.util.Objects.requireNonNull;
024
025/** An atomic candidate published only after every PATCH operation and final schema check succeeds.
026 * This value is neither authorization nor proof of persistence. Applications own version/timestamp updates.
027 * @since 1.0.0
028 */
029@Immutable
030@CheckReturnValue
031public final class ScimPatchResult {
032    private final @NonNull ScimResource resource;
033    private final boolean modified;
034    private final @NonNull Set<@NonNull ScimAttributePath> requestedAttributePaths;
035    private final @NonNull Set<@NonNull ScimAttributePath> modifiedAttributePaths;
036    private final @NonNull Set<@NonNull ScimAttributePath> suppliedAttributePaths;
037    private final @NonNull Object semanticContext;
038    ScimPatchResult(@NonNull ScimResource resource, boolean modified,
039            @NonNull Set<@NonNull ScimAttributePath> requested, @NonNull Set<@NonNull ScimAttributePath> changed,
040            @NonNull Set<@NonNull ScimAttributePath> supplied, @NonNull Object context) {
041        this.resource=requireNonNull(resource); this.modified=modified; requestedAttributePaths=Set.copyOf(requested);
042        modifiedAttributePaths=Set.copyOf(changed); suppliedAttributePaths=Set.copyOf(supplied); semanticContext=requireNonNull(context);
043    }
044    /** Returns the complete candidate resource.
045     * @return the resource
046     * @since 1.0.0 */
047    public @NonNull ScimResource getResource() { return resource; }
048    /** Returns whether the final resource differs from the original after all ordered operations.
049     * @return the final difference flag
050     * @since 1.0.0 */
051    public @NonNull Boolean isModified() { return modified; }
052    /** Returns all conservative attempted and selector paths, including no-op attempts.
053     * @return the immutable requested paths
054     * @since 1.0.0 */
055    public @NonNull Set<@NonNull ScimAttributePath> getRequestedAttributePaths() { return requestedAttributePaths; }
056    /** Returns conservative effective paths, including induced primary/container/schema changes.
057     * @return the immutable modified paths
058     * @since 1.0.0 */
059    public @NonNull Set<@NonNull ScimAttributePath> getModifiedAttributePaths() { return modifiedAttributePaths; }
060    /** Returns canonical paths actually supplied by the request, for write-response projection.
061     * @return the immutable supplied paths
062     * @since 1.0.0 */
063    public @NonNull Set<@NonNull ScimAttributePath> getSuppliedAttributePaths() { return suppliedAttributePaths; }
064    @NonNull Object getSemanticContext() { return semanticContext; }
065    /** Returns a fixed redacted description.
066     * @return the description
067     * @since 1.0.0 */
068    @Override public @NonNull String toString() { return "ScimPatchResult{<redacted>}"; }
069}