package com.atlassian.webdriver.bitbucket.page;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class LicenseEditPage extends BitbucketPage {
    @Override
    public String getUrl() {
        return "/admin/license?edit";
    }

    public String getServerId() {
        return driver.findElement(By.id("serverid")).getText();
    }
    
    public String getLicense() {
        return driver.findElement(By.id("license")).getText();
    }
    
    public LicenseEditPage setLicense(String license) {
        WebElement licenseElement = driver.findElement(By.id("license"));
        licenseElement.clear();
        licenseElement.sendKeys(license);
        return this;
    }
    
    public String getLicenseError() {
        WebElement error = driver.findElement(By.cssSelector("#license + .error"));
        if (error != null) {
            return error.getText();
        }
        return null;
    }
    
    public LicensePage saveSuccessfully() {
        driver.findElement(By.id("submit")).click();
        return pageBinder.bind(LicensePage.class);
    }
    
    public LicenseEditPage saveUnsuccessfully() {
        driver.findElement(By.id("submit")).click();
        return pageBinder.bind(LicenseEditPage.class);
    }
    
    public LicensePage cancel() {
        driver.findElement(By.id("cancel")).click();
        return pageBinder.bind(LicensePage.class);
    }
}
