package com.atlassian.webdriver.bitbucket.page;

import com.atlassian.pageobjects.elements.ElementBy;
import com.atlassian.pageobjects.elements.PageElement;
import org.openqa.selenium.By;

public class UserAccountNotificationSettingsPage extends BitbucketPage {

    private static final String NOTIFICATION_SEND_MODE_ID = "notification-send-mode";

    @ElementBy(className = "notification-settings-form")
    private PageElement settingsForm;

    @Override
    public String getUrl() {
        return "/plugins/servlet/notification/settings";
    }

    public String getSelectedSendMode() {
        PageElement selectedMode = settingsForm.find(By.cssSelector("input:checked"));
        return selectedMode.getAttribute("value");
    }

    public void save() {
        settingsForm.find(By.className("save")).click();
    }

    public UserAccountNotificationSettingsPage setSelectedSendMode(String newMode) {
        PageElement mode = settingsForm.find(By.id("setting-" + newMode.toLowerCase()));
        if (mode == null) {
            throw new IllegalArgumentException("Option for mode " + newMode + " does not exist!");
        }
        mode.select();
        return this;
    }
}
