package com.atlassian.webdriver.bitbucket.page;

import com.atlassian.pageobjects.elements.ElementBy;
import com.atlassian.pageobjects.elements.PageElement;
import com.atlassian.webdriver.bitbucket.element.DiffSelectionDropdown;
import com.atlassian.webdriver.bitbucket.element.UnifiedDiffFileContent;

public class ChangesetUnifiedDiffPage extends CommitPage<ChangesetUnifiedDiffPage, UnifiedDiffFileContent> {

    @ElementBy(id = "diff-options-dropdown-trigger")
    protected PageElement dropdown;

    @ElementBy(className ="file-content", pageElementClass = UnifiedDiffFileContent.class)
    protected UnifiedDiffFileContent fileContent;

    public ChangesetUnifiedDiffPage(String projectKey, String repoSlug, String commitId) {
        this(projectKey, repoSlug, commitId, null, null);
    }

    public ChangesetUnifiedDiffPage(String projectKey, String repoSlug, String commitId, String parentId) {
        this(projectKey, repoSlug, commitId, parentId, null);
    }

    public ChangesetUnifiedDiffPage(String projectKey, String repoSlug, String commitId, String parentId, String changePath) {
        super(projectKey, repoSlug, commitId, parentId, changePath, ChangesetUnifiedDiffPage.class);
    }

    @Override
    public UnifiedDiffFileContent getFileContent() {
        return fileContent;
    }

    public ChangesetSideBySideDiffPage switchToSideBySide() {
        pageBinder.bind(DiffSelectionDropdown.class, dropdown).open().selectSideBySide();
        ChangesetSideBySideDiffPage page = pageBinder.bind(ChangesetSideBySideDiffPage.class, projectKey, repoSlug, commitId, parentId, changePath);
        page.getFileContent().waitUntilFileContentLoaded();
        return page;
    }
}
