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;
022
023import org.jspecify.annotations.NonNull;
024
025import java.util.*;
026
027import javax.annotation.concurrent.Immutable;
028
029/** Provider-constructible match outcome, without arbitrary failure data.
030 * @since 1.0.0
031 */
032@Immutable
033public sealed interface ScimStringMatchResult
034        permits ScimStringMatchResult.Matched, ScimStringMatchResult.Unsupported {
035    /** Creates a matching verdict.
036     * @param value verdict
037     * @return outcome
038     * @since 1.0.0
039     */
040    @CheckReturnValue
041    static @NonNull ScimStringMatchResult fromMatched(@NonNull Boolean value) {
042        return new Matched(requireNonNull(value));
043    }
044
045    /** Reports unsupported matching.
046     * @return fixed outcome
047     * @since 1.0.0
048     */
049    @CheckReturnValue
050    static @NonNull ScimStringMatchResult unsupportedInstance() {
051        return Unsupported.INSTANCE;
052    }
053
054    /** A matching verdict.
055     * @since 1.0.0
056     */
057    @Immutable
058    final class Matched implements ScimStringMatchResult {
059        private final boolean matched;
060
061        private Matched(boolean value) {
062            matched = value;
063        }
064
065        /** Returns the verdict.
066         * @return matching state
067         * @since 1.0.0
068         */
069        public @NonNull Boolean isMatched() {
070            return matched;
071        }
072
073        /** Returns a fixed diagnostic.
074         * @return description
075         * @since 1.0.0
076         */
077        @Override
078        public @NonNull String toString() {
079            return "ScimStringMatchResult.Matched";
080        }
081    }
082
083    /** Matching is unsupported.
084     * @since 1.0.0
085     */
086    @Immutable
087    final class Unsupported implements ScimStringMatchResult {
088        private static final @NonNull Unsupported INSTANCE = new Unsupported();
089
090        private Unsupported() {}
091
092        /** Returns a fixed diagnostic.
093         * @return description
094         * @since 1.0.0
095         */
096        @Override
097        public @NonNull String toString() {
098            return "ScimStringMatchResult.Unsupported";
099        }
100    }
101}