package com.hubspot.baragon.models;

import com.google.common.collect.ImmutableMap;

public class InternalStatesMap {
  private static final ImmutableMap<InternalRequestStates, AgentRequestType> stateToRequestTypeMap = new ImmutableMap.Builder<InternalRequestStates, AgentRequestType>()
    .put(InternalRequestStates.PENDING, AgentRequestType.APPLY)
    .put(InternalRequestStates.INVALID_REQUEST_NOOP, AgentRequestType.APPLY)
    .put(InternalRequestStates.SEND_APPLY_REQUESTS, AgentRequestType.APPLY)
    .put(InternalRequestStates.CHECK_APPLY_RESPONSES, AgentRequestType.APPLY)
    .put(InternalRequestStates.COMPLETED, AgentRequestType.APPLY)
    .put(InternalRequestStates.FAILED_SEND_REVERT_REQUESTS, AgentRequestType.REVERT)
    .put(InternalRequestStates.FAILED_CHECK_REVERT_RESPONSES, AgentRequestType.REVERT)
    .put(InternalRequestStates.FAILED_REVERT_FAILED, AgentRequestType.REVERT)
    .put(InternalRequestStates.CANCELLED_SEND_REVERT_REQUESTS, AgentRequestType.CANCEL)
    .put(InternalRequestStates.CANCELLED_CHECK_REVERT_RESPONSES, AgentRequestType.CANCEL)
    .put(InternalRequestStates.CANCELLED, AgentRequestType.CANCEL)
    .put(InternalRequestStates.FAILED_CANCEL_FAILED, AgentRequestType.CANCEL)
    .build();

  private static final ImmutableMap<InternalRequestStates, BaragonRequestState> stateToRequestStateMap = new ImmutableMap.Builder<InternalRequestStates, BaragonRequestState>()
    .put(InternalRequestStates.PENDING, BaragonRequestState.WAITING)
    .put(InternalRequestStates.INVALID_REQUEST_NOOP, BaragonRequestState.INVALID_REQUEST_NOOP)
    .put(InternalRequestStates.SEND_APPLY_REQUESTS, BaragonRequestState.WAITING)
    .put(InternalRequestStates.CHECK_APPLY_RESPONSES, BaragonRequestState.WAITING)
    .put(InternalRequestStates.COMPLETED, BaragonRequestState.SUCCESS)
    .put(InternalRequestStates.FAILED_SEND_REVERT_REQUESTS, BaragonRequestState.WAITING)
    .put(InternalRequestStates.FAILED_REVERTED, BaragonRequestState.FAILED)
    .put(InternalRequestStates.FAILED_CHECK_REVERT_RESPONSES, BaragonRequestState.WAITING)
    .put(InternalRequestStates.FAILED_REVERT_FAILED, BaragonRequestState.FAILED)
    .put(InternalRequestStates.CANCELLED_SEND_REVERT_REQUESTS, BaragonRequestState.CANCELING)
    .put(InternalRequestStates.CANCELLED_CHECK_REVERT_RESPONSES, BaragonRequestState.CANCELING)
    .put(InternalRequestStates.CANCELLED, BaragonRequestState.CANCELED)
    .put(InternalRequestStates.FAILED_CANCEL_FAILED, BaragonRequestState.FAILED)
    .build();

  private static final ImmutableMap<AgentRequestType, ImmutableMap<String, InternalRequestStates>> typeToRequestStateMap = new ImmutableMap.Builder<AgentRequestType, ImmutableMap<String, InternalRequestStates>>()
    .put(AgentRequestType.APPLY, ImmutableMap.of("waiting", InternalRequestStates.CHECK_APPLY_RESPONSES, "failure", InternalRequestStates.FAILED_SEND_REVERT_REQUESTS, "retry", InternalRequestStates.SEND_APPLY_REQUESTS, "success", InternalRequestStates.COMPLETED))
    .put(AgentRequestType.REVERT, ImmutableMap.of("waiting", InternalRequestStates.FAILED_CHECK_REVERT_RESPONSES, "failure", InternalRequestStates.FAILED_REVERT_FAILED, "retry", InternalRequestStates.FAILED_SEND_REVERT_REQUESTS, "success", InternalRequestStates.FAILED_REVERTED))
    .put(AgentRequestType.CANCEL, ImmutableMap.of("waiting", InternalRequestStates.CANCELLED_CHECK_REVERT_RESPONSES, "failure", InternalRequestStates.FAILED_CANCEL_FAILED, "retry", InternalRequestStates.CANCELLED_SEND_REVERT_REQUESTS, "success", InternalRequestStates.CANCELLED))
    .build();

  public static InternalRequestStates getWaitingState(InternalRequestStates requestState) {
    return typeToRequestStateMap.get(stateToRequestTypeMap.get(requestState)).get("waiting");
  }

  public static InternalRequestStates getFailureState(InternalRequestStates requestState) {
    return typeToRequestStateMap.get(stateToRequestTypeMap.get(requestState)).get("failure");
  }

  public static InternalRequestStates getRetryState(InternalRequestStates requestState) {
    return typeToRequestStateMap.get(stateToRequestTypeMap.get(requestState)).get("retry");
  }

  public static InternalRequestStates getSuccessState(InternalRequestStates requestState) {
    return typeToRequestStateMap.get(stateToRequestTypeMap.get(requestState)).get("success");
  }

  public static AgentRequestType getRequestType(InternalRequestStates requestState) {
    return stateToRequestTypeMap.get(requestState);
  }

  public static BaragonRequestState getRequestState(InternalRequestStates requestState) {
    return stateToRequestStateMap.get(requestState);
  }

  public static boolean isCancelable(InternalRequestStates requestState) {
    return stateToRequestStateMap.get(requestState) == BaragonRequestState.WAITING;
  }

  public static boolean isRemovable(InternalRequestStates requestState) {
    BaragonRequestState state = stateToRequestStateMap.get(requestState);
    return state == BaragonRequestState.SUCCESS || state == BaragonRequestState.FAILED || state == BaragonRequestState.CANCELED;
  }

}

@@ -2558,38 +2558,51 @@
 e, ImmutableMap%3C
-String
+AgentRequestsStatus
 , InternalReques
@@ -2695,14 +2695,27 @@
 Map%3C
-String
+AgentRequestsStatus
 , In
@@ -2783,33 +2783,51 @@
 tableMap.of(
-%22waiting%22
+AgentRequestsStatus.WAITING
 , InternalRe
@@ -2857,33 +2857,51 @@
 _RESPONSES, 
-%22failure%22
+AgentRequestsStatus.FAILURE
 , InternalRe
@@ -2941,23 +2941,41 @@
 QUESTS, 
-%22retry%22
+AgentRequestsStatus.RETRY
 , Intern
@@ -3007,33 +3007,51 @@
 Y_REQUESTS, 
-%22success%22
+AgentRequestsStatus.SUCCESS
 , InternalRe
@@ -3120,33 +3120,51 @@
 tableMap.of(
-%22waiting%22
+AgentRequestsStatus.WAITING
 , InternalRe
@@ -3202,33 +3202,51 @@
 _RESPONSES, 
-%22failure%22
+AgentRequestsStatus.FAILURE
 , InternalRe
@@ -3271,39 +3271,57 @@
 _REVERT_FAILED, 
-%22retry%22
+AgentRequestsStatus.RETRY
 , InternalReques
@@ -3353,33 +3353,51 @@
 T_REQUESTS, 
-%22success%22
+AgentRequestsStatus.SUCCESS
 , InternalRe
@@ -3476,25 +3476,43 @@
 eMap.of(
-%22waiting%22
+AgentRequestsStatus.WAITING
 , Intern
@@ -3561,25 +3561,43 @@
 PONSES, 
-%22failure%22
+AgentRequestsStatus.FAILURE
 , Intern
@@ -3634,23 +3634,41 @@
 FAILED, 
-%22retry%22
+AgentRequestsStatus.RETRY
 , Intern
@@ -3715,25 +3715,43 @@
 QUESTS, 
-%22success%22
+AgentRequestsStatus.SUCCESS
 , Intern

use AgentRequestsStatus enum