package com.atlassian.webdriver.bitbucket.page;

import org.openqa.selenium.By;

public class PullRequestCommitDiffPage extends PullRequestDiffPage {

    private final String commitHash;

    public PullRequestCommitDiffPage(String projectKey, String slug, long pullRequestId, String commitHash) {
        this(projectKey, slug, pullRequestId, commitHash, null);
    }

    public PullRequestCommitDiffPage(String projectKey, String slug, long pullRequestId, String commitHash, String path) {
        super(projectKey, slug, pullRequestId, path);

        this.commitHash = commitHash;
    }

    public PullRequestCommitDiffPage(String projectKey, String slug, long pullRequestId, String commitHash,
                                     long commentId, String action) {
        super(projectKey, slug, pullRequestId, commentId, action);

        this.commitHash = commitHash;
    }

    public String getCommitHash() {
        return commitHash;
    }

    public CommitUnifiedDiffPage visitStandaloneCommit() {
        this.elementFinder.find(By.cssSelector(".file-tree-header .commitid")).click();
        return pageBinder.bind(CommitUnifiedDiffPage.class, getProjectKey(), getSlug(), getCommitHash());
    }

    @Override
    protected String getDiffUrl() {
        return "/commits/" + commitHash;
    }
}
