package com.atlassian.stash.internal.idx;

import com.atlassian.bitbucket.repository.Repository;

import java.io.Serializable;
import java.util.function.Function;

public class HierarchyIndexingRequest implements Serializable {

    public static final Function<HierarchyIndexingRequest, String> BUCKET_EXTRACTOR = HierarchyIndexingRequest::getHierarchyId;

    private final String hierarchyId;
    private final int repositoryId;

    public HierarchyIndexingRequest(Repository repository) {
        this(repository.getId(), repository.getHierarchyId());
    }

    public HierarchyIndexingRequest(int repositoryId, String hierarchyId) {
        this.repositoryId = repositoryId;
        this.hierarchyId = hierarchyId;
    }

    public String getHierarchyId() {
        return hierarchyId;
    }

    public int getRepositoryId() {
        return repositoryId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        return repositoryId == ((HierarchyIndexingRequest) o).repositoryId;
    }

    @Override
    public int hashCode() {
        return repositoryId;
    }
}
