package com.atlassian.stash.experimental.user;

import com.atlassian.annotations.ExperimentalApi;
import com.atlassian.bitbucket.project.Project;
import com.google.common.base.Objects;

import javax.annotation.Nonnull;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Queries the project permissions given to users.
 *
 * WARNING: this interface is experimental and is subject to change between minor versions of Stash up to and including
 * removal of this interface or parts thereof. It is not for consumption by non-Atlassian plugins and no consideration
 * will be given to nor guarantees made for its compatibility between releases. Basically, don't use it unless
 * you're a Stash developer.
 *
 * @since 2.12
 */
@ExperimentalApi
public class PermittedUserProjectSearchRequest extends PermittedUserSearchRequest {
    private final Project project;

    protected PermittedUserProjectSearchRequest(@Nonnull ProjectBuilder builder) {
        super(builder);

        this.project = checkNotNull(builder.project, "project");
    }

    @Nonnull
    public Project getProject() {
        return project;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(project, getUserType(), getNameFilter());
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        final PermittedUserProjectSearchRequest other = (PermittedUserProjectSearchRequest) obj;
        return Objects.equal(this.project, other.project) && Objects.equal(this.getUserType(), other.getUserType())
                && Objects.equal(this.getNameFilter(), other.getNameFilter());
    }

    @Override
    public <T> T accept(@Nonnull Visitor<T> visitor) {
        return visitor.visit(this);
    }
}
