package com.autonomy.abc.selenium.page.admin;

import com.autonomy.abc.selenium.element.FormInput;
import com.autonomy.abc.selenium.users.HSOUser;
import com.autonomy.abc.selenium.users.Role;
import com.autonomy.abc.selenium.users.Status;
import com.hp.autonomy.frontend.selenium.element.ModalView;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class HSOUsersPage extends UsersPage {
    public HSOUsersPage(WebDriver driver) {
        super(driver);
        waitForLoad();
    }

    public FormInput getUsernameInput(){
        return new FormInput(getDriver().findElement(By.id("create-users-username")), getDriver());
    }

    public FormInput getEmailInput(){
        return new FormInput(getDriver().findElement(By.className("create-user-email-input")), getDriver());
    }

    public WebElement getUserLevelDropdown(){
        return getDriver().findElement(By.id("create-users-role"));
    }

    public void addEmail(String email) {
        getEmailInput().setValue(email);
    }

    public WebElement refreshButton() {
        return findElement(By.id("refresh-users"));
    }

    public WebElement getUserRow(HSOUser user){
        return findElement(By.xpath("//*[contains(@class,'user-email') and text()='" + user.getEmail() + "']/.."));
    }

    public Status getStatusOf(HSOUser user) {
        return Status.fromString(getUserRow(user).findElement(By.className("account-status")).getText());
    }

    public Role getRoleOf(HSOUser user) {
        return Role.fromString(roleLinkFor(user).getText());
    }

    public WebElement roleLinkFor(HSOUser user){
        return getUserRow(user).findElement(By.cssSelector(".user-role a"));
    }

    public void selectRoleFor(HSOUser user, Role newRole) {
        getUserRow(user).findElement(By.xpath(".//option[contains(text(),'"+newRole+"')]")).click();
    }

    public void submitPendingEditFor(HSOUser user) {
        getUserRow(user).findElement(By.cssSelector(".editable-submit")).click();
    }

    private WebElement getUserRowByUsername(String username){
        return findElement(By.xpath("//*[contains(@class,'user-name') and text()='" + username + "']/.."));
    }

    private By trashCan(){
        return By.className("users-deleteUser");
    }

    @Override
    public void deleteUser(String username){
        getUserRowByUsername(username).findElement(trashCan()).click();
        ModalView.getVisibleModalView(getDriver()).okButton().click();
    }
}

@@ -232,16 +232,61 @@
 Status;%0A
+import com.autonomy.abc.selenium.users.User;%0A
 import c
@@ -1233,19 +1233,16 @@
 UserRow(
-HSO
 User use
@@ -1331,21 +1331,33 @@
 t()='%22 +
+ ((HSOUser)
  user
+)
 .getEmai
@@ -1410,19 +1410,16 @@
 tatusOf(
-HSO
 User use
@@ -1562,19 +1562,16 @@
 tRoleOf(
-HSO
 User use
@@ -1673,27 +1673,24 @@
 roleLinkFor(
-HSO
 User user)%7B%0A
@@ -1799,27 +1799,24 @@
 lectRoleFor(
-HSO
 User user, R
@@ -1975,19 +1975,16 @@
 EditFor(
-HSO
 User use

Change HSOUser to User in HSOUsersPage so it overrides methods in the superclass