package com.hubspot.blazar.externalservice.slack;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Objects;
import com.google.common.base.Optional;

@JsonIgnoreProperties(ignoreUnknown = true)
public class SlackApiResponse {

  private final boolean ok;
  private final Optional<String> error;
  private Optional<List<SlackChannel>> channels;

  @JsonCreator
  public SlackApiResponse(@JsonProperty("ok") boolean ok,
                          @JsonProperty("error") Optional<String> error,
                          @JsonProperty("channels") Optional<List<SlackChannel>> channels) {
    this.ok = ok;
    this.error = error;
    this.channels = channels;
  }

  public boolean getOk() {
    return ok;
  }

  public Optional<String> getError() {
    return error;
  }

  public Optional<List<SlackChannel>> getChannels() {
    return channels;
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(this)
        .add("ok", ok)
        .add("error", error.get())
        .toString();
  }

}

@@ -1062,22 +1062,42 @@
 ) %7B%0A    
-return
+Objects.ToStringHelper h =
  Objects
@@ -1117,25 +1117,23 @@
 er(this)
+;
 %0A    
-    
+h
 .add(%22ok
@@ -1138,25 +1138,54 @@
 ok%22, ok)
+;
 %0A    
-    
+if (error.isPresent()) %7B%0A      h
 .add(%22er
@@ -1202,25 +1202,101 @@
 r.get())
+;
 %0A    
-    
+%7D else %7B%0A      h.add(%22error%22, Optional.absent().toString());%0A    %7D%0A    return h
 .toStrin

remove optional wrapper around the error message