package com.atlassian.stash.experimental.user;

import com.atlassian.annotations.ExperimentalApi;
import com.atlassian.bitbucket.repository.Repository;
import com.google.common.base.Objects;

import javax.annotation.Nonnull;

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

/**
 * Queries the repository 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 PermittedUserRepositorySearchRequest extends PermittedUserSearchRequest {
    private Repository repository;

    protected PermittedUserRepositorySearchRequest(@Nonnull RepositoryBuilder builder) {
        super(builder);
        this.repository = checkNotNull(builder.repository, "repository");
    }

    @Nonnull
    public Repository getRepository() {
        return repository;
    }

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

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        final PermittedUserRepositorySearchRequest other = (PermittedUserRepositorySearchRequest) obj;
        return Objects.equal(this.repository, other.repository) && 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);
    }
}
