package com.l7tech.external.assertions.gatewaygraphql.server.data;

import com.fasterxml.jackson.annotation.JsonIncludeProperties;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.l7tech.external.assertions.gatewaygraphql.server.resolver.helper.ClusterNodeInfoHelper;
import com.l7tech.gateway.common.cluster.ClusterNodeInfo;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class ClusterNodeInfoDTO extends NonEntityDTO {
   public static String ACTIVE_STATUS;
   public static String INACTIVE_STATUS;
   private final ClusterNodeInfo a;
   private final ClusterNodeInfoHelper b;
   private final String c;
   private List<LicenseInfoDTO> d;
   private ClusterNodeInfoHelper.OSInfo e;
   private ClusterNodeInfoHelper.JVMInfo f;
   private ClusterNodeInfoHelper.ProductVersion g;
   private List<ClusterNodeInfoHelper.PatchInfo> h;
   private List<EntityProperty> i;
   private List<EntityProperty> j;
   private List<EntityProperty> k;
   private List<EntityProperty> l;

   public ClusterNodeInfoDTO(ClusterNodeInfo var1, ClusterNodeInfoHelper var2, String var3) {
      this.a = var1;
      this.b = var2;
      this.c = var3;
   }

   @Override
   protected Object createWrapperObject() {
      return new ClusterNodeInfoDTO.ClusterNodeInfoWrapper(this.a, this.b, this.c);
   }

   public String getNodeId() {
      return this.a.getNodeIdentifier();
   }

   public String getName() {
      return this.a.getName();
   }

   public String getAddress() {
      return this.a.getAddress();
   }

   public long getUptime() {
      return this.a.getUptime();
   }

   public String getBootTime() {
      return a(this.a.getBootTime());
   }

   public String getLastUpdatedTime() {
      return a(this.a.getLastUpdateTimeStamp());
   }

   public String getNodeStatus() {
      if (this.a.getId().equals(this.c)) {
         return ACTIVE_STATUS;
      } else {
         return System.currentTimeMillis() < this.a.getLastUpdateTimeStamp() + 10000L ? ACTIVE_STATUS : INACTIVE_STATUS;
      }
   }

   public ClusterNodeInfoDTO.FormFactor getFormFactor() {
      return this.b.getFormFactor();
   }

   public boolean isSupportsDBUpgrade() {
      return this.b.isSupportsDBUpgrade();
   }

   public boolean isFailoverDBConfigured() {
      return this.b.isFailoverDBConfigured();
   }

   public ClusterNodeInfoHelper.OSInfo getOperatingSystem() {
      if (this.e == null) {
         this.e = this.b.getOSInfo();
      }

      return this.e;
   }

   public ClusterNodeInfoHelper.JVMInfo getJvm() {
      if (this.f == null) {
         this.f = this.b.getJVMInfo();
      }

      return this.f;
   }

   public List<EntityProperty> getJvmArguments() {
      if (this.i == null) {
         this.i = a(this.b.getJVMArguments());
      }

      return this.i;
   }

   public String productName() {
      return this.b.getProductName();
   }

   public ClusterNodeInfoHelper.ProductVersion getProductVersion() {
      if (this.g == null) {
         this.g = this.b.getProductVersion();
      }

      return this.g;
   }

   public List<LicenseInfoDTO> getLicenses() {
      if (this.d == null) {
         this.d = this.b.getLicenseDetails();
      }

      return this.d;
   }

   public List<ClusterNodeInfoHelper.PatchInfo> getPatches() {
      if (this.h == null) {
         this.h = this.b.getPatches();
      }

      return this.h;
   }

   public List<EntityProperty> getSystemProperties() {
      if (this.j == null) {
         this.j = a(this.b.getSystemProperties());
      }

      return this.j;
   }

   public List<EntityProperty> getTelemetryProperties() {
      if (this.k == null) {
         this.k = a(this.b.getTelemetryProperties());
      }

      return this.k;
   }

   public List<EntityProperty> getNodeProperties() {
      if (this.l == null) {
         this.l = a(this.b.getNodeProperties());
      }

      return this.l;
   }

   private static List<EntityProperty> a(Properties var0) {
      ArrayList var1 = new ArrayList();

      for (String var4 : var0.stringPropertyNames()) {
         String var5 = var0.getProperty(var4);
         var1.add(new EntityProperty(var4, var5));
      }

      return var1;
   }

   private static String a(long var0) {
      return var0 <= 0L ? null : Instant.ofEpochMilli(var0).atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
   }

   static {
      String[] var0 = new String[2];
      int var4 = 0;
      String var3 = "i`vr\n#Ne\u0006amcx\b/";
      int var5 = "i`vr\n#Ne\u0006amcx\b/".length();
      char var2 = '\b';
      int var1 = -1;

      while (true) {
         String var10002 = a(64, a(var3.substring(++var1, var1 + var2)));
         byte var10001 = -1;
         var0[var4++] = var10002;
         if ((var1 += var2) >= var5) {
            ACTIVE_STATUS = var0[1];
            INACTIVE_STATUS = var0[0];
            return;
         }

         var2 = var3.charAt(var1);
      }
   }

   private static char[] a(String var0) {
      char[] var10000 = var0.toCharArray();
      if (var10000.length < 2) {
         var10000[0] = (char)(var10000[0] ^ 88);
      }

      return var10000;
   }

   private static String a(int var0, char[] var1) {
      int var10003 = var1.length;
      int var10002 = var0;
      char[] var10001 = var1;
      int var10000 = var10003;

      for (int var2 = 0; var10000 > var2; var2++) {
         var10001[var2] = (char)(var10001[var2] ^ var10002 ^ switch (var2 % 7) {
            case 0 -> 96;
            case 1 -> 110;
            case 2 -> 119;
            case 3 -> 113;
            case 4 -> 30;
            case 5 -> 42;
            default -> 88;
         });
      }

      return new String(var10001).intern();
   }

   @JsonIncludeProperties(
      {
            "nodeId",
            "name",
            "address",
            "licenses",
            "productName",
            "productVersion",
            "operatingSystem",
            "jvm",
            "patches",
            "jvmArguments",
            "systemProperties",
            "telemetryProperties",
            "nodeProperties"
      }
   )
   @JsonPropertyOrder(
      {
            "nodeId",
            "name",
            "address",
            "licenses",
            "productName",
            "productVersion",
            "operatingSystem",
            "jvm",
            "patches",
            "jvmArguments",
            "systemProperties",
            "telemetryProperties",
            "nodeProperties"
      }
   )
   public static class ClusterNodeInfoWrapper extends ClusterNodeInfoDTO {
      public ClusterNodeInfoWrapper(ClusterNodeInfo var1, ClusterNodeInfoHelper var2, String var3) {
         super(var1, var2, var3);
      }

      @Override
      protected Object createWrapperObject() {
         return null;
      }
   }

   public enum FormFactor {
      APPLIANCE,
      SOFTWARE,
      CONTAINER,
      UNKNOWN;

      // $VF: Failed to inline enum fields
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      static {
         String[] var0 = new String[4];
         int var4 = 0;
         String var3 = "\u001a](\u0018~i\n\t\f\\-\u0002pw\n\nA";
         int var5 = "\u001a](\u0018~i\n\t\f\\-\u0002pw\n\nA".length();
         char var2 = 7;
         int var7 = -1;

         label25:
         while (true) {
            byte var10000 = 114;
            String var10001 = var3.substring(++var7, var7 + var2);
            byte var10002 = -1;

            while (true) {
               String var8 = a(var10000, a(var10001));
               switch (var10002) {
                  case 0:
                     var0[var4++] = var8;
                     if ((var7 += var2) >= var5) {
                        APPLIANCE = new ClusterNodeInfoDTO.FormFactor();
                        SOFTWARE = new ClusterNodeInfoDTO.FormFactor();
                        CONTAINER = new ClusterNodeInfoDTO.FormFactor();
                        UNKNOWN = new ClusterNodeInfoDTO.FormFactor();
                        return;
                     }

                     var2 = var3.charAt(var7);
                     break;
                  default:
                     var0[var4++] = var8;
                     if ((var7 += var2) < var5) {
                        var2 = var3.charAt(var7);
                        continue label25;
                     }

                     var3 = "@\r}T61DB\u0018\bR\u0012kL(1XD";
                     var5 = "@\r}T61DB\u0018\bR\u0012kL(1XD".length();
                     var2 = '\t';
                     var7 = -1;
               }

               var10000 = 60;
               var10001 = var3.substring(++var7, var7 + var2);
               var10002 = 0;
            }
         }
      }

      private static char[] a(String var0) {
         char[] var10000 = var0.toCharArray();
         if (var10000.length < 2) {
            var10000[0] = (char)(var10000[0] ^ 54);
         }

         return var10000;
      }

      private static String a(int var0, char[] var1) {
         int var10003 = var1.length;
         int var10002 = var0;
         char[] var10001 = var1;
         int var10000 = var10003;

         for (int var2 = 0; var10000 > var2; var2++) {
            var10001[var2] = (char)(var10001[var2] ^ var10002 ^ switch (var2 % 7) {
               case 0 -> 61;
               case 1 -> 97;
               case 2 -> 17;
               case 3 -> 36;
               case 4 -> 67;
               case 5 -> 76;
               default -> 54;
            });
         }

         return new String(var10001).intern();
      }
   }
}
