package com.atlassian.webdriver.bitbucket.page;

import com.atlassian.pageobjects.elements.ElementBy;
import com.atlassian.pageobjects.elements.PageElement;
import com.atlassian.webdriver.bitbucket.element.AccessKeyRow;
import com.atlassian.webdriver.bitbucket.util.Locators;

import java.util.List;

public class RepositoryAccessKeySettingsPage extends BaseRepositoryPage {

    @ElementBy(id = "ssh-keys-table")
    private PageElement sshKeysTable;

    public RepositoryAccessKeySettingsPage(String projectKey, String slug) {
        super(projectKey, slug);
    }

    @Override
    public String getUrl() {
        return String.format("/plugins/servlet/ssh/projects/%s/repos/%s/keys", getProjectKey(), getSlug());
    }

    public List<AccessKeyRow> getAccessKeys() {
        return sshKeysTable.findAll(Locators.tableRow(), AccessKeyRow.class);
    }

    public boolean isEmpty() {
        return getAccessKeys().isEmpty();
    }
}
