package com.atlassian.bitbucket.internal.mirroring.mirror.sync;

import javax.annotation.Nonnull;
import java.io.Serializable;
import java.util.Objects;

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

public class RepositoryFetchTask implements Serializable {
    private static final long serialVersionUID = 1L;

    private final String cloneUrl;
    private final String contentHash;
    private final String hierarchyId;
    private final int repositoryId;
    private final String upstreamId;

    public RepositoryFetchTask(String upstreamId, int repositoryId, String hierarchyId, String contentHash, String cloneUrl) {

        this.cloneUrl = checkNotNull(cloneUrl, "cloneUrl");
        this.contentHash = checkNotNull(contentHash, "hash");
        this.hierarchyId = checkNotNull(hierarchyId, "hierarchyId");
        this.repositoryId = repositoryId;
        this.upstreamId = checkNotNull(upstreamId, "upstreamId");
    }

    @Nonnull
    public String getCloneUrl() {
        return cloneUrl;
    }

    @Nonnull
    public String getContentHash() {
        return contentHash;
    }

    @Nonnull
    public String getHierarchyId() {
        return hierarchyId;
    }

    public int getRepositoryId() {
        return repositoryId;
    }

    @Nonnull
    public String getUpstreamId() {
        return upstreamId;
    }

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

        RepositoryFetchTask other = (RepositoryFetchTask) o;

        return Objects.equals(repositoryId, other.repositoryId) &&
                Objects.equals(upstreamId, other.upstreamId) &&
                Objects.equals(contentHash, other.contentHash) &&
                Objects.equals(cloneUrl, other.cloneUrl);
    }

    @Override
    public int hashCode() {
        return Objects.hash(repositoryId, upstreamId, contentHash, cloneUrl);
    }
}
