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.saml;
018
019import org.jspecify.annotations.NonNull;
020import javax.annotation.concurrent.Immutable;
021import java.util.Objects;
022
023/**
024 * Storage provider outcomes when consuming a pending SAML login or logout.
025 *
026 * @since 1.0.0
027 */
028@Immutable
029public sealed interface SamlPendingConsumeResult permits SamlPendingConsumeResult.Consumed,
030        SamlPendingConsumeResult.Missing, SamlPendingConsumeResult.Unavailable,
031        SamlPendingConsumeResult.Indeterminate {
032    /**
033     * A record removed atomically.
034     *
035     * @since 1.0.0
036     */
037    @Immutable
038    final class Consumed implements SamlPendingConsumeResult {
039        private final @NonNull String sealedRecord;
040        private Consumed(@NonNull String sealedRecord) { this.sealedRecord = Objects.requireNonNull(sealedRecord); }
041        /**
042         * Creates a provider result for an atomically removed record.
043         *
044         * @param sealedRecord opaque Revetsec record
045         * @return a consumed outcome
046         * @since 1.0.0
047         */
048        public static @NonNull Consumed fromSealedRecord(@NonNull String sealedRecord) {
049            return new Consumed(sealedRecord);
050        }
051        /**
052         * Returns the sealed record for Revetsec to authenticate.
053         *
054         * @return sealed record
055         * @since 1.0.0
056         */
057        public @NonNull String getSealedRecord() { return sealedRecord; }
058        /**
059         * Redacts the record.
060         *
061         * @return redacted description
062         * @since 1.0.0
063         */
064        @Override public @NonNull String toString() { return "SamlPendingConsumeResult.Consumed{<redacted>}"; }
065    }
066    /**
067     * No eligible live record matches the binding, handle and any consume condition.
068     * A record refused by a condition remains unconsumed.
069     *
070     * @since 1.0.0
071     */
072    @Immutable
073    enum Missing implements SamlPendingConsumeResult { /** No eligible record. */ INSTANCE }
074    /**
075     * The store failed before a mutation.
076     *
077     * @since 1.0.0
078     */
079    @Immutable
080    enum Unavailable implements SamlPendingConsumeResult { /** No mutation occurred. */ INSTANCE }
081    /**
082     * The consume outcome cannot be determined.
083     *
084     * @since 1.0.0
085     */
086    @Immutable
087    enum Indeterminate implements SamlPendingConsumeResult { /** Reconciliation is required. */ INSTANCE }
088}