package com.atlassian.stash.experimental.user;

import com.atlassian.annotations.ExperimentalApi;
import com.google.common.base.Objects;

import javax.annotation.Nonnull;

/**
 * Used to query the repositories a user is permitted to access.
 *
 * 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 RepositoryPermissionSearchRequest extends ResourcePermissionRequest {
    private RepositoryPermissionSearchRequest(@Nonnull Builder builder) {
        super(builder);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getUser());
    }

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

    public static class Builder extends AbstractBuilder<Builder, RepositoryPermissionSearchRequest> {
        public Builder() {
        }

        public Builder(@Nonnull RepositoryPermissionSearchRequest request) {
            super(request);
        }

        @Override
        public RepositoryPermissionSearchRequest build() {
            return new RepositoryPermissionSearchRequest(this);
        }

        @Override
        protected Builder self() {
            return this;
        }
    }
}
