package com.l7tech.external.assertions.gatewaygraphql.server.resolver.mutation;

import com.l7tech.external.assertions.gatewaygraphql.EntityTypeInfo;
import com.l7tech.external.assertions.gatewaygraphql.server.data.EntityMappingInstruction;
import com.l7tech.external.assertions.gatewaygraphql.server.data.FipGroupDTO;
import com.l7tech.external.assertions.gatewaygraphql.server.resolver.query.IdpResolverHelper;
import com.l7tech.identity.IdentityProviderType;
import com.l7tech.identity.fed.FederatedGroup;
import com.l7tech.identity.fed.FederatedUser;
import com.l7tech.objectmodel.FindException;
import com.l7tech.server.identity.fed.FederatedGroupManager;
import com.l7tech.server.identity.fed.FederatedIdentityProvider;
import graphql.schema.DataFetchingEnvironment;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.transaction.PlatformTransactionManager;

@Deprecated
public class FederatedIdpGroupMutationResolver
   extends IdpGroupMutationResolver<FederatedIdentityProvider, FederatedGroup, FederatedUser, FipGroupDTO, FipGroupDTO.FipGroupInput> {
   private static final String[] c;

   public FederatedIdpGroupMutationResolver(PlatformTransactionManager var1, BeanFactory var2, IdpResolverHelper var3) {
      super(EntityTypeInfo.FEDERATED_GROUP, var1, var3, IdentityProviderType.FEDERATED);
   }

   public FipGroupDTO.FipGroupsPayload setFipGroups(List<FipGroupDTO.FipGroupInput> var1, DataFetchingEnvironment var2) {
      FipGroupDTO.FipGroupsPayload var3 = new FipGroupDTO.FipGroupsPayload();
      this.transformNoDefEntityMappings(var1, var2);
      return var1.isEmpty() ? var3 : this.execute(var2, (var3x, var4) -> {
         var1.forEach(var4x -> this.doUpsertSilently(var4x, var3x, var3, var4));
         return var3;
      });
   }

   public FipGroupDTO.FipGroupsPayload deleteFipGroups(String var1, List<String> var2, DataFetchingEnvironment var3) {
      FipGroupDTO.FipGroupsPayload var4 = new FipGroupDTO.FipGroupsPayload();
      return var2.isEmpty() ? var4 : this.execute(var3, (var4x, var5) -> {
         var2.forEach(var5x -> this.doDeleteSilently(var1, var5x, var4x, var4, var5));
         return var4;
      });
   }

   protected FederatedGroup toEntity(FederatedIdentityProvider var1, FipGroupDTO.FipGroupInput var2) {
      return new FederatedGroup(var1.getConfig().getGoid(), var2.getName());
   }

   protected FipGroupDTO toEntityDTO(FederatedIdentityProvider var1, FederatedGroup var2) {
      return new FipGroupDTO(var2, var1, this.idpHelper);
   }

   protected FipGroupDTO.FipGroupInput toEntityInput(EntityMappingInstruction var1) {
      FipGroupDTO.FipGroupInput var2 = new FipGroupDTO.FipGroupInput();
      var2.setName(var1.getIdentityValue());
      var2.setProviderName(var1.getSourceString(c[0]));
      return var2;
   }

   protected Map<String, Object> toRawEntity(@Nullable FipGroupDTO.FipGroupInput var1) {
      Map var2 = super.toRawEntity(var1);
      if (var1 != null) {
         var2.put(c[1], var1.getProviderName());
      }

      return var2;
   }

   protected void setEntity(FederatedIdentityProvider var1, FipGroupDTO.FipGroupInput var2, FederatedGroup var3) {
      var3.setDescription(var2.getDescription());
   }

   protected FederatedGroup doFind(FederatedIdentityProvider var1, FipGroupDTO.FipGroupInput var2) throws FindException {
      return (FederatedGroup)((FederatedGroupManager)var1.getGroupManager()).findByName(var2.getName());
   }

   protected FederatedIdentityProvider doFindIdp(FipGroupDTO.FipGroupInput var1) throws FindException {
      return this.doFindIdp(var1.getProviderName());
   }

   static {
      String[] var5 = new String[2];
      int var3 = 0;
      String var2 = "\u0007\u0004\u0004\"6\u001f\u0013\u00058\n9:\f\u0007\u0004\u0004\"6\u001f\u0013\u00058\n9:";
      int var4 = "\u0007\u0004\u0004\"6\u001f\u0013\u00058\n9:\f\u0007\u0004\u0004\"6\u001f\u0013\u00058\n9:".length();
      char var1 = '\f';
      int var0 = -1;

      while (true) {
         String var10002 = d(91, c(var2.substring(++var0, var0 + var1)));
         byte var10001 = -1;
         var5[var3++] = var10002;
         if ((var0 += var1) >= var4) {
            c = var5;
            return;
         }

         var1 = var2.charAt(var0);
      }
   }

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

      return var10000;
   }

   private static String d(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 -> 44;
            case 1 -> 45;
            case 2 -> 48;
            case 3 -> 15;
            case 4 -> 4;
            case 5 -> 32;
            default -> 45;
         });
      }

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