package com.atlassian.stash.internal.pull.rescope;

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

/**
 * Represents a {@link com.atlassian.bitbucket.scm.pull.PullRequestRescope} resulting in the associated pull request
 * being marked as merged.
 *
 * @since 4.5
 */
public class MergeOutcome implements RescopeOutcome {

    private final String mergeHash;

    public MergeOutcome(String mergeHash) {
        this.mergeHash = mergeHash;
    }

    @Override
    public <T> T accept(@Nonnull RescopeOutcomeVisitor<T> visitor) {
        return visitor.visit(this);
    }

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

    /**
     * @return the merge hash, if one was determined
     */
    @Nullable
    public String getMergeHash() {
        return mergeHash;
    }

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