package com.hubspot.baragon.service.config;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import org.hibernate.validator.constraints.NotEmpty;

import java.util.Locale;

import javax.validation.Valid;
import javax.validation.constraints.Pattern;

import static com.google.common.base.Preconditions.checkNotNull;

public class UIConfiguration {

  public static enum RootUrlMode {
    UI_REDIRECT,
    INDEX_CATCHALL,
    DISABLED;

    public static RootUrlMode parse(String value) {
      checkNotNull(value, "value is null");
      value = value.toUpperCase(Locale.ENGLISH);

      for (RootUrlMode rootUrlMode : RootUrlMode.values()) {
        String name = rootUrlMode.name();
        if (name.equals(value) || name.replace("_", "").equals(value)) {
          return rootUrlMode;
        }
      }

      throw new IllegalArgumentException("Value '" + value + "' unknown");
    }
  }

  @NotEmpty
  @JsonProperty
  private String title = "Baragon";

  @JsonProperty
  @Pattern( regexp = "^|#[0-9a-fA-F]{6}$" )
  private String navColor = "";

  @JsonProperty
  private String baseUrl;

  private boolean readOnly = true;

  /**
   * If true, the root of the server (http://.../singularity/) will open the UI. Otherwise,
   * the UI URI (http://.../singularity/ui/) must be used.
   */
  @JsonProperty
  private String rootUrlMode = RootUrlMode.INDEX_CATCHALL.name();

  public boolean isReadOnly() {
    return readOnly;
  }

  public void setReadOnly(boolean readOnly) {
    this.readOnly = readOnly;
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public Optional<String> getBaseUrl() {
    return Optional.fromNullable(Strings.emptyToNull(baseUrl));
  }

  public void setBaseUrl(String baseUrl) {
    this.baseUrl = baseUrl;
  }

  public String getNavColor() {
    return navColor;
  }

  public void setNavColor(String navColor) {
    this.navColor = navColor;
  }

  @Valid
  public RootUrlMode getRootUrlMode() {
    return RootUrlMode.parse(rootUrlMode);
  }

  /**
   * Supports 'uiRedirect', 'indexCatchall' and 'disabled'.
   *
   * <ul>
   * <li>uiRedirect - UI is served off <tt>/ui</tt> path and index redirects there.</li>
   * <li>indexCatchall - UI is served off <tt>/</tt> using a catchall resource.</li>
   * <li>disabled> - UI is served off <tt>/ui> and the root resource is not served at all.</li>
   * </ul>
   *
   * @param rootUrlMode A valid root url mode.
   */
  public void setRootUrlMode(String rootUrlMode) {
    this.rootUrlMode = rootUrlMode;
  }
}

@@ -432,2222 +432,824 @@
 %0A%0A  
-public static enum RootUrlMode %7B%0A    UI_REDIRECT,%0A    INDEX_CATCHALL,%0A    DISABLED;%0A%0A    public static RootUrlMode parse(String value) %7B%0A      checkNotNull(value, %22value is null%22);%0A      value = value.toUpperCase(Locale.ENGLISH);%0A%0A      for (RootUrlMode rootUrlMode : RootUrlMode.values()) %7B%0A        String name = rootUrlMode.name();%0A        if (name.equals(value) %7C%7C name.replace(%22_%22, %22%22).equals(value)) %7B%0A          return rootUrlMode;%0A        %7D%0A      %7D%0A%0A      throw new IllegalArgumentException(%22Value '%22 + value + %22' unknown%22);%0A    %7D%0A  %7D%0A%0A  @NotEmpty%0A  @JsonProperty%0A  private String title = %22Baragon%22;%0A%0A  @JsonProperty%0A  @Pattern( regexp = %22%5E%7C#%5B0-9a-fA-F%5D%7B6%7D$%22 )%0A  private String navColor = %22%22;%0A%0A  @JsonProperty%0A  private String baseUrl;%0A%0A  private boolean readOnly = true;%0A%0A  /**%0A   * If true, the root of the server (http://.../singularity/) will open the UI. Otherwise,%0A   * the UI URI (http://.../singularity/ui/) must be used.%0A   */%0A  @JsonProperty%0A  private String rootUrlMode = RootUrlMode.INDEX_CATCHALL.name();%0A%0A  public boolean isReadOnly() %7B%0A    return readOnly;%0A  %7D%0A%0A  public void setReadOnly(boolean readOnly) %7B%0A    this.readOnly = readOnly;%0A  %7D%0A%0A  public String getTitle() %7B%0A    return title;%0A  %7D%0A%0A  public void setTitle(String title) %7B%0A    this.title = title;%0A  %7D%0A%0A  public Optional%3CString%3E getBaseUrl() %7B%0A    return Optional.fromNullable(Strings.emptyToNull(baseUrl));%0A  %7D%0A%0A  public void setBaseUrl(String baseUrl) %7B%0A    this.baseUrl = baseUrl;%0A  %7D%0A%0A  public String getNavColor() %7B%0A    return navColor;%0A  %7D%0A%0A  public void setNavColor(String navColor) %7B%0A    this.navColor = navColor;%0A  %7D%0A%0A  @Valid%0A  public RootUrlMode getRootUrlMode() %7B%0A    return RootUrlMode.parse(rootUrlMode);%0A  %7D%0A%0A  /**%0A   * Supports 'uiRedirect', 'indexCatchall' and 'disabled'.%0A   *%0A   * %3Cul%3E%0A   * %3Cli%3EuiRedirect - UI is served off %3Ctt%3E/ui%3C/tt%3E path and index redirects there.%3C/li%3E%0A   * %3Cli%3EindexCatchall - UI is served off %3Ctt%3E/%3C/tt%3E using a catchall resource.%3C/li%3E%0A   * %3Cli%3Edisabled%3E - UI is served off %3Ctt%3E/ui%3E and the root resource is not served at all.%3C/li%3E%0A   * %3C/ul%3E%0A   *%0A   * @param rootUrlMode A valid root url mode.%0A   */%0A  public void setRootUrlMode(String rootUrlMode) %7B%0A    this.rootUrlMode = rootUrlMode;%0A  %7D
+@NotEmpty%0A  @JsonProperty%0A  private String title = %22Baragon%22;%0A%0A  @JsonProperty%0A  @Pattern( regexp = %22%5E%7C#%5B0-9a-fA-F%5D%7B6%7D$%22 )%0A  private String navColor = %22%22;%0A%0A  @JsonProperty%0A  private String baseUrl;%0A%0A  private boolean readOnly = true;%0A%0A  public boolean isReadOnly() %7B%0A    return readOnly;%0A  %7D%0A%0A  public void setReadOnly(boolean readOnly) %7B%0A    this.readOnly = readOnly;%0A  %7D%0A%0A  public String getTitle() %7B%0A    return title;%0A  %7D%0A%0A  public void setTitle(String title) %7B%0A    this.title = title;%0A  %7D%0A%0A  public Optional%3CString%3E getBaseUrl() %7B%0A    return Optional.fromNullable(Strings.emptyToNull(baseUrl));%0A  %7D%0A%0A  public void setBaseUrl(String baseUrl) %7B%0A    this.baseUrl = baseUrl;%0A  %7D%0A%0A  public String getNavColor() %7B%0A    return navColor;%0A  %7D%0A%0A  public void setNavColor(String navColor) %7B%0A    this.navColor = navColor;%0A  %7D%0A
 %0A%7D%0A

remove unused items in UI config