package com.intland.codebeamer.functionaltest.page.systemadmin;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.SelenideElement;
import com.intland.codebeamer.functionaltest.page.BasePage;
import com.intland.codebeamer.functionaltest.page.ServiceDeskPage;
import org.openqa.selenium.By;

import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.page;

public class SystemAdminPage extends BasePage {

    private SelenideElement setManagedRepositoryAccessURLsSelector = $(By.xpath(".//a[@href='/cb/sysadmin/setMRAccessUrl.spr']"));
    private SelenideElement userGroupsSelector = $(By.xpath(".//a[@href='/cb/sysadmin/userGroups.spr']"));

    public UsersPage clickOnUserAccounts() {
        $(By.partialLinkText("User Accounts")).click();
        return page(UsersPage.class);
    }

    public ServiceDeskPage clickOnServiceDesk() {
        $(By.partialLinkText("Service Desk Configuration")).click();
        return page(ServiceDeskPage.class);
    }

    public ProjectListPage clickOnProjectList() {
        $(By.xpath(".//a[@href='/cb/sysadmin/projectsList.spr']")).click();
        return page(ProjectListPage.class);
    }

    public SetManagedRepositoryPage clickOnSetManagedRepository() {
        $(By.xpath(".//a[@href='/cb/sysadmin/setMRAccessUrl.spr']")).click();
        return page(SetManagedRepositoryPage.class);
}

    public LicensePage clickOnLicense() {
        $(By.xpath(".//a[@href='/cb/sysadmin/configLicense.spr']")).click();
        return page(LicensePage.class);
    }

    public UserGroupsPage clickOnUserGroups() {
        userGroupsSelector.click();
        return page(UserGroupsPage.class);
    }

    public DocumentsPage clickOnDocumentsLink() {
        $(By.partialLinkText("Documents")).click();
        return page(DocumentsPage.class);
    }

    public void checkIfSetManagedRepositoryAccessURLs(Condition condition) {
        setManagedRepositoryAccessURLsSelector.shouldBe(condition);
    }


}
