package mil.dds.anet.beans;

import io.leangen.graphql.annotations.GraphQLInputField;
import io.leangen.graphql.annotations.GraphQLQuery;
import io.leangen.graphql.annotations.GraphQLRootContext;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import mil.dds.anet.AnetObjectEngine;
import mil.dds.anet.utils.Utils;
import mil.dds.anet.views.AbstractAnetBean;

public class ApprovalStep extends AbstractAnetBean {

  public static enum ApprovalStepType {
    PLANNING_APPROVAL, REPORT_APPROVAL
  }

  @GraphQLQuery
  @GraphQLInputField
  ApprovalStepType type;
  // annotated below
  List<Position> approvers;
  @GraphQLQuery
  @GraphQLInputField
  String nextStepUuid;
  @GraphQLQuery
  @GraphQLInputField
  String relatedObjectUuid;
  @GraphQLQuery
  @GraphQLInputField
  String name;
  @GraphQLQuery
  @GraphQLInputField
  private boolean restrictedApproval;

  @GraphQLQuery(name = "approvers")
  public CompletableFuture<List<Position>> loadApprovers(
      @GraphQLRootContext Map<String, Object> context) {
    if (approvers != null) {
      return CompletableFuture.completedFuture(approvers);
    }
    return AnetObjectEngine.getInstance().getApprovalStepDao().getApproversForStep(context, uuid)
        .thenApply(o -> {
          approvers = o;
          return o;
        });
  }

  public List<Position> getApprovers() {
    return approvers;
  }

  @GraphQLInputField(name = "approvers")
  public void setApprovers(List<Position> approvers) {
    this.approvers = approvers;
  }

  public String getNextStepUuid() {
    return nextStepUuid;
  }

  public void setNextStepUuid(String nextStepUuid) {
    this.nextStepUuid = nextStepUuid;
  }

  public String getRelatedObjectUuid() {
    return relatedObjectUuid;
  }

  public void setRelatedObjectUuid(String relatedObjectUuid) {
    this.relatedObjectUuid = relatedObjectUuid;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = Utils.trimStringReturnNull(name);
  }

  public ApprovalStepType getType() {
    return type;
  }

  public void setType(ApprovalStepType type) {
    this.type = type;
  }

  public boolean isRestrictedApproval() {
    return restrictedApproval;
  }

  public void setRestrictedApproval(boolean restrictedApproval) {
    this.restrictedApproval = restrictedApproval;
  }

  @Override
  public boolean equals(Object o) {
    if (!(o instanceof ApprovalStep)) {
      return false;
    }
    ApprovalStep as = (ApprovalStep) o;
    return Objects.equals(uuid, as.getUuid()) && Objects.equals(name, as.getName())
        && Objects.equals(nextStepUuid, as.getNextStepUuid()) && Objects.equals(type, as.getType())
        && Objects.equals(relatedObjectUuid, as.getRelatedObjectUuid())
        && Objects.equals(restrictedApproval, as.isRestrictedApproval());
  }

  @Override
  public int hashCode() {
    return Objects.hash(uuid, approvers, name, nextStepUuid, relatedObjectUuid, type,
        restrictedApproval);
  }

  @Override
  public String toString() {
    return String.format("%s - %s, aoid: %s, nsid: %s", uuid, name, relatedObjectUuid,
        nextStepUuid);
  }

}

@@ -855,42 +855,26 @@
 ;%0A  
-@GraphQLQuery%0A  @GraphQLInputField
+// annotated below
 %0A  p
@@ -880,17 +880,17 @@
 private 
-b
+B
 oolean r
@@ -2163,32 +2163,48 @@
 pe = type;%0A  %7D%0A%0A
+  @GraphQLQuery%0A
   public boolean
@@ -2240,16 +2240,36 @@
  return 
+Boolean.TRUE.equals(
 restrict
@@ -2278,23 +2278,45 @@
 Approval
+)
 ;%0A  %7D%0A%0A
+  @GraphQLInputField%0A
   public
@@ -2343,17 +2343,17 @@
 pproval(
-b
+B
 oolean r
@@ -2608,20 +2608,25 @@
 .equals(
-u
+getU
 uid
+()
 , as.get
@@ -2651,20 +2651,25 @@
 .equals(
-n
+getN
 ame
+()
 , as.get
@@ -2702,17 +2702,20 @@
 .equals(
-n
+getN
 extStepU
@@ -2713,24 +2713,26 @@
 NextStepUuid
+()
 , as.getNext
@@ -2738,24 +2738,32 @@
 tStepUuid())
+%0A       
  && Objects.
@@ -2769,20 +2769,25 @@
 .equals(
-t
+getT
 ype
+()
 , as.get
@@ -2820,17 +2820,20 @@
 .equals(
-r
+getR
 elatedOb
@@ -2840,16 +2840,18 @@
 jectUuid
+()
 , as.get
@@ -2889,33 +2889,35 @@
  Objects.equals(
-r
+isR
 estrictedApprova
@@ -2917,16 +2917,18 @@
 Approval
+()
 , as.isR

Make approvalStep.restrictedApproval optional