package com.atlassian.stash.internal.integrity;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

/**
 * Represents an 'event' in the application integrity check process.
 * These are currently the only values allowed as the key for {@link InternalIntegrityEvent the integrity event entity}
 * and can be persisted with a timestamp.
 *
 * @since 4.8
 */
public enum IntegrityEventKey {

    ACKNOWLEDGED("acknowledged"),
    COMPLETED("completed"),
    INCONSISTENCY("inconsistency"),
    STARTED("started");

    private final String id;

    IntegrityEventKey(String id) {
        this.id = id;
    }

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

    @Nonnull
    public static IntegrityEventKey fromId(@Nonnull String id) {
        requireNonNull(id, "id");

        for (IntegrityEventKey eventKey : values()) {
            if (eventKey.getId().equalsIgnoreCase(id)) {
                return eventKey;
            }
        }

        throw new IllegalArgumentException("No event key with the specified id exists");
    }
}
