package com.atlassian.stash.internal.scm.git.protocol;

import com.google.common.base.MoreObjects;

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

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

/**
 * A path to a repository - includes its optional namespace, project key and repo slug.
 */
public class RepositoryPath {

    private final String namespace;
    private final String projectKey;
    private final String repoSlug;

    public RepositoryPath(String namespace, @Nonnull String projectKey,
                          @Nonnull String repoSlug) {
        this.namespace = namespace;
        this.projectKey = checkNotNull(projectKey, "projectKey");
        this.repoSlug = checkNotNull(repoSlug, "repoSlug");
    }


    public String getNamespace() {
        return namespace;
    }

    @Nonnull
    public String getProjectKey() {
        return projectKey;
    }

    @Nonnull
    public String getRepositorySlug() {
        return repoSlug;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        RepositoryPath that = (RepositoryPath) o;
        return Objects.equals(namespace, that.namespace) &&
                Objects.equals(projectKey, that.projectKey) &&
                Objects.equals(repoSlug, that.repoSlug);
    }

    @Override
    public int hashCode() {
        return Objects.hash(namespace, projectKey, repoSlug);
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("namespace", namespace)
                .add("projectKey", projectKey)
                .add("repoSlug", repoSlug)
                .toString();
    }
}
