package com.atlassian.bitbucket.repository.ref.restriction;

import javax.annotation.Nonnull;

/**
 * The type of restriction on a {@link RefRestriction}.
 */
public enum RefRestrictionType {

    /**
     * No changes to a ref are allowed at all
     */
    READ_ONLY("read-only", true),
    /**
     * Ref cannot be deleted
     */
    NO_DELETES("no-deletes", false),
    /**
     * No rebases or force pushes
     */
    FAST_FORWARD_ONLY("fast-forward-only", false),
    /**
     * Ref can only be updated through forced pushes
     */
    PULL_REQUEST_ONLY("pull-request-only", false);

    private final String id;
    private final boolean supportsPermissions;

    RefRestrictionType(String id, boolean supportsPermissions) {
        this.id = id;
        this.supportsPermissions = supportsPermissions;
    }

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

    public boolean supportsPermissions() {
        return supportsPermissions;
    }

    public static RefRestrictionType forId(@Nonnull String id) {
        for (RefRestrictionType value : values()) {
            if (value.getId().equals(id)) {
                return value;
            }
        }
        throw new IllegalArgumentException("There is no RefRestrictionType for ID " + id);
    }
}
