package com.hubspot.singularity;

import java.util.List;
import java.util.Map;

import com.google.common.base.Optional;
import com.hubspot.deploy.ExecutorData;
import com.hubspot.mesos.Resources;

public class SingularityDeployBuilder {

  private final String requestId;
  private final String id;

  private Optional<String> version;
  private Optional<Long> timestamp;
  private Optional<Map<String, String>> metadata;

  private Optional<String> customExecutorCmd;
  private Optional<String> customExecutorId;
  private Optional<Resources> resources;
 
  private Optional<String> command;
  private Optional<Map<String, String>> env;
  private Optional<List<String>> uris;
  private Optional<ExecutorData> executorData;
 
  private Optional<String> healthcheckUri;
  private Optional<Long> healthcheckIntervalSeconds;
  private Optional<Long> healthcheckTimeoutSeconds;
  
  private Optional<Long> deployHealthTimeoutSeconds;
  
  private Optional<Long> considerHealthyAfterRunningForSeconds;

  private Optional<String> serviceBasePath;
  private Optional<List<String>> loadBalancerGroups;
  private Optional<Map<String, Object>> loadBalancerOptions;

  public SingularityDeployBuilder(String requestId, String id) {
    this.requestId = requestId;
    this.id = id;
    this.version = Optional.absent();
    this.timestamp = Optional.absent();
    this.metadata = Optional.absent();
    this.customExecutorCmd = Optional.absent();
    this.customExecutorId = Optional.absent();
    this.resources = Optional.absent();
    this.command = Optional.absent();
    this.env = Optional.absent();
    this.uris = Optional.absent();
    this.executorData = Optional.absent();
    this.healthcheckUri = Optional.absent();
    this.healthcheckIntervalSeconds = Optional.absent();
    this.healthcheckTimeoutSeconds = Optional.absent();
    this.deployHealthTimeoutSeconds = Optional.absent();
    this.considerHealthyAfterRunningForSeconds = Optional.absent();
    this.serviceBasePath = Optional.absent();
    this.loadBalancerGroups = Optional.absent();
    this.loadBalancerOptions = Optional.absent();
  }
  
  public SingularityDeploy build() {
    return new SingularityDeploy(requestId, id, command, customExecutorCmd, customExecutorId, resources, env, uris, metadata, executorData, version, timestamp, deployHealthTimeoutSeconds, healthcheckUri, healthcheckIntervalSeconds, 
        healthcheckTimeoutSeconds, serviceBasePath, loadBalancerGroups, considerHealthyAfterRunningForSeconds, loadBalancerOptions);
  }

  public String getRequestId() {
    return requestId;
  }

  public String getId() {
    return id;
  }
  
  public Optional<Long> getConsiderHealthyAfterRunningForSeconds() {
    return considerHealthyAfterRunningForSeconds;
  }

  public SingularityDeployBuilder setConsiderHealthyAfterRunningForSeconds(Optional<Long> considerHealthyAfterRunningForSeconds) {
    this.considerHealthyAfterRunningForSeconds = considerHealthyAfterRunningForSeconds;
    return this;
  }

  public Optional<String> getVersion() {
    return version;
  }

  public SingularityDeployBuilder setVersion(Optional<String> version) {
    this.version = version;
    return this;
  }

  public Optional<Long> getTimestamp() {
    return timestamp;
  }

  public SingularityDeployBuilder setTimestamp(Optional<Long> timestamp) {
    this.timestamp = timestamp;
    return this;
  }

  public Optional<Map<String, String>> getMetadata() {
    return metadata;
  }

  public SingularityDeployBuilder setMetadata(Optional<Map<String, String>> metadata) {
    this.metadata = metadata;
    return this;
  }
    
  public Optional<String> getCustomExecutorCmd() {
    return customExecutorCmd;
  }

  public SingularityDeployBuilder setCustomExecutorCmd(Optional<String> customExecutorCmd) {
    this.customExecutorCmd = customExecutorCmd;
    return this;
  }

  public Optional<String> getCustomExecutorId() {
    return customExecutorId;
  }

  public SingularityDeployBuilder setCustomExecutorId(Optional<String> customExecutorId) {
    this.customExecutorId = customExecutorId;
    return this;
  }

  public Optional<Long> getDeployHealthTimeoutSeconds() {
    return deployHealthTimeoutSeconds;
  }

  public SingularityDeployBuilder setDeployHealthTimeoutSeconds(Optional<Long> deployHealthTimeoutSeconds) {
    this.deployHealthTimeoutSeconds = deployHealthTimeoutSeconds;
    return this;
  }

  public Optional<Resources> getResources() {
    return resources;
  }

  public SingularityDeployBuilder setResources(Optional<Resources> resources) {
    this.resources = resources;
    return this;
  }

  public Optional<String> getCommand() {
    return command;
  }

  public SingularityDeployBuilder setCommand(Optional<String> command) {
    this.command = command;
    return this;
  }

  public Optional<Map<String, String>> getEnv() {
    return env;
  }

  public SingularityDeployBuilder setEnv(Optional<Map<String, String>> env) {
    this.env = env;
    return this;
  }

  public Optional<List<String>> getUris() {
    return uris;
  }

  public SingularityDeployBuilder setUris(Optional<List<String>> uris) {
    this.uris = uris;
    return this;
  }

  public Optional<ExecutorData> getExecutorData() {
    return executorData;
  }

  public SingularityDeployBuilder setExecutorData(Optional<ExecutorData> executorData) {
    this.executorData = executorData;
    return this;
  }

  public Optional<String> getHealthcheckUri() {
    return healthcheckUri;
  }

  public SingularityDeployBuilder setHealthcheckUri(Optional<String> healthcheckUri) {
    this.healthcheckUri = healthcheckUri;
    return this;
  }

  public Optional<Long> getHealthcheckIntervalSeconds() {
    return healthcheckIntervalSeconds;
  }

  public SingularityDeployBuilder setHealthcheckIntervalSeconds(Optional<Long> healthcheckIntervalSeconds) {
    this.healthcheckIntervalSeconds = healthcheckIntervalSeconds;
    return this;
  }

  public Optional<Long> getHealthcheckTimeoutSeconds() {
    return healthcheckTimeoutSeconds;
  }

  public SingularityDeployBuilder setHealthcheckTimeoutSeconds(Optional<Long> healthcheckTimeoutSeconds) {
    this.healthcheckTimeoutSeconds = healthcheckTimeoutSeconds;
    return this;
  }

  public Optional<String> getServiceBasePath() {
    return serviceBasePath;
  }

  public SingularityDeployBuilder setServiceBasePath(Optional<String> serviceBasePath) {
    this.serviceBasePath = serviceBasePath;
    return this;
  }

  public Optional<List<String>> getLoadBalancerGroups() {
    return loadBalancerGroups;
  }

  public SingularityDeployBuilder setLoadBalancerGroups(Optional<List<String>> loadBalancerGroups) {
    this.loadBalancerGroups = loadBalancerGroups;
    return this;
  }

  public Optional<Map<String, Object>> getLoadBalancerOptions() {
    return loadBalancerOptions;
  }

  public SingularityDeployBuilder setLoadBalancerOptions(Optional<Map<String, Object>> loadBalancerOptions) {
    this.loadBalancerOptions = loadBalancerOptions;
    return this;
  }

  @Override
  public String toString() {
    return "SingularityDeployBuilder [" +
        "requestId='" + requestId + '\'' +
        ", id='" + id + '\'' +
        ", version=" + version +
        ", timestamp=" + timestamp +
        ", metadata=" + metadata +
        ", customExecutorCmd=" + customExecutorCmd +
        ", customExecutorId=" + customExecutorId +
        ", resources=" + resources +
        ", command=" + command +
        ", env=" + env +
        ", uris=" + uris +
        ", executorData=" + executorData +
        ", healthcheckUri=" + healthcheckUri +
        ", healthcheckIntervalSeconds=" + healthcheckIntervalSeconds +
        ", healthcheckTimeoutSeconds=" + healthcheckTimeoutSeconds +
        ", deployHealthTimeoutSeconds=" + deployHealthTimeoutSeconds +
        ", considerHealthyAfterRunningForSeconds=" + considerHealthyAfterRunningForSeconds +
        ", serviceBasePath=" + serviceBasePath +
        ", loadBalancerGroups=" + loadBalancerGroups +
        ", loadBalancerOptions=" + loadBalancerOptions +
        ']';
  }
}

@@ -261,24 +261,25 @@
  requestId;%0A
+%0A
   private fi
@@ -272,30 +272,24 @@
 %0A%0A  private 
-final 
 String id;%0A%0A
@@ -2605,32 +2605,125 @@
 turn id;%0A  %7D%0A  %0A
+  public SingularityDeployBuilder setId(String id) %7B%0A    this.id = id;%0A    return this;%0A  %7D%0A%0A
   public Optiona

allow deploy builder to set ID.