package com.atlassian.bitbucket.internal.mirroring;

import javax.annotation.Nonnull;
import java.util.Locale;

/**
 * Reflects the state of a request by a server to act as a mirror
 *
 * @since 4.2
 */
public enum MirroringRequestState {
    /**
     * Indicates the request is neither accepted nor rejected
     */
    PENDING,
    /**
     * Indicates the request was been accepted
     */
    ACCEPTED,
    /**
     * Indicates the request was rejected
     */
    REJECTED;

    private final String id;

    MirroringRequestState() {
        this.id = name().toLowerCase(Locale.US);
    }

    @Nonnull
    public String getId() {
        return id;
    }

    @Nonnull
    public static MirroringRequestState fromId(@Nonnull String value) {
        for (MirroringRequestState state : values()) {
            if (state.getId().equals(value)) {
                return state;
            }
        }

        throw new IllegalArgumentException("No MirroringRequestState exists for ID " + value);
    }
}
