package com.hubspot.singularity;

import com.google.common.base.Optional;
import com.hubspot.mesos.protos.MesosTaskState;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema
public enum ExtendedTaskState {

  TASK_LAUNCHED("launched", false, Optional.absent()), TASK_STAGING("staging", false, Optional.of(MesosTaskState.TASK_STAGING)),
  TASK_STARTING("starting", false, Optional.of(MesosTaskState.TASK_STARTING)), TASK_RUNNING("running", false, Optional.of(MesosTaskState.TASK_RUNNING)),
  TASK_CLEANING("cleaning", false, Optional.absent()), TASK_KILLING("killing", false, Optional.of(MesosTaskState.TASK_KILLING)), TASK_FINISHED("finished", true, Optional.of(MesosTaskState.TASK_FINISHED)),
  TASK_FAILED("failed", true, Optional.of(MesosTaskState.TASK_FAILED)), TASK_KILLED("killed", true, Optional.of(MesosTaskState.TASK_KILLED)),
  TASK_LOST("lost", true, Optional.of(MesosTaskState.TASK_LOST)), TASK_LOST_WHILE_DOWN("lost", true, Optional.absent()), TASK_ERROR("error", true, Optional.of(MesosTaskState.TASK_ERROR)),
  TASK_DROPPED("dropped", true, Optional.of(MesosTaskState.TASK_DROPPED)), TASK_GONE("gone", true, Optional.of(MesosTaskState.TASK_GONE)), TASK_UNREACHABLE("unreachable", true, Optional.of(MesosTaskState.TASK_UNREACHABLE)),
  TASK_GONE_BY_OPERATOR("goneByOperator", true, Optional.of(MesosTaskState.TASK_GONE_BY_OPERATOR)), TASK_UNKNOWN("dropped", true, Optional.of(MesosTaskState.TASK_UNKNOWN));

  private final String displayName;
  private final boolean isDone;
  private final Optional<MesosTaskState> taskState;

  ExtendedTaskState(String displayName, boolean isDone, Optional<MesosTaskState> taskState) {
    this.displayName = displayName;
    this.isDone = isDone;
    this.taskState = taskState;
  }

  public String getDisplayName() {
    return displayName;
  }

  public boolean isDone() {
    return isDone;
  }

  public boolean isFailed() {
    return this == TASK_FAILED;
  }

  public boolean isSuccess() {
    return this == TASK_FINISHED;
  }

  public Optional<MesosTaskState> toTaskState() {
    return taskState;
  }
}

@@ -208,17 +208,16 @@
 State %7B%0A
-%0A
   TASK_L
@@ -259,24 +259,27 @@
 .absent()), 
+%0A  
 TASK_STAGING
@@ -415,24 +415,27 @@
 STARTING)), 
+%0A  
 TASK_RUNNING
@@ -547,24 +547,27 @@
 .absent()), 
+%0A  
 TASK_KILLING
@@ -624,24 +624,27 @@
 _KILLING)), 
+%0A  
 TASK_FINISHE
@@ -775,24 +775,27 @@
 K_FAILED)), 
+%0A  
 TASK_KILLED(
@@ -914,24 +914,27 @@
 ASK_LOST)), 
+%0A  
 TASK_LOST_WH
@@ -972,24 +972,27 @@
 .absent()), 
+%0A  
 TASK_ERROR(%22
@@ -1117,24 +1117,27 @@
 _DROPPED)), 
+%0A  
 TASK_GONE(%22g
@@ -1184,24 +1184,27 @@
 ASK_GONE)), 
+%0A  
 TASK_UNREACH
@@ -1376,16 +1376,19 @@
 ATOR)), 
+%0A  
 TASK_UNK

Improve ExtendedTaskState readability