package com.l7tech.server.task;

import com.l7tech.gateway.common.security.rbac.OperationType;
import com.l7tech.gateway.common.security.rbac.PermissionDeniedException;
import com.l7tech.gateway.common.task.ScheduledTask;
import com.l7tech.gateway.common.task.ScheduledTaskAdmin;
import com.l7tech.identity.User;
import com.l7tech.objectmodel.DeleteException;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.SaveException;
import com.l7tech.objectmodel.UpdateException;
import com.l7tech.server.security.rbac.RbacServices;
import com.l7tech.server.util.JaasUtils;
import jakarta.inject.Inject;
import java.util.Collection;
import org.jetbrains.annotations.NotNull;

public class ScheduledTaskAdminImpl implements ScheduledTaskAdmin {
   @Inject
   private ScheduledTaskManager scheduledTaskManager;
   @Inject
   private RbacServices rbacServices;
   private static final String[] a;

   public ScheduledTask getScheduledTask(Goid var1) throws FindException {
      return (ScheduledTask)this.scheduledTaskManager.findByPrimaryKey(var1);
   }

   public Collection<ScheduledTask> getAllScheduledTasks() throws FindException {
      return this.scheduledTaskManager.findAll();
   }

   public Goid saveScheduledTask(ScheduledTask param1) throws UpdateException, SaveException {
      // $VF: Couldn't be decompiled
      // 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!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aload 1
      // 01: invokevirtual com/l7tech/gateway/common/task/ScheduledTask.getGoid ()Lcom/l7tech/objectmodel/Goid;
      // 04: ifnull 18
      // 07: aload 1
      // 08: invokevirtual com/l7tech/gateway/common/task/ScheduledTask.getGoid ()Lcom/l7tech/objectmodel/Goid;
      // 0b: invokestatic com/l7tech/objectmodel/Goid.isDefault (Lcom/l7tech/objectmodel/Goid;)Z
      // 0e: ifeq 20
      // 11: goto 18
      // 14: invokestatic com/l7tech/server/task/ScheduledTaskAdminImpl.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 17: athrow
      // 18: bipush 1
      // 19: goto 21
      // 1c: invokestatic com/l7tech/server/task/ScheduledTaskAdminImpl.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 1f: athrow
      // 20: bipush 0
      // 21: istore 2
      // 22: aload 1
      // 23: invokevirtual com/l7tech/gateway/common/task/ScheduledTask.getIdProviderGoid ()Lcom/l7tech/objectmodel/Goid;
      // 26: ifnonnull 37
      // 29: aload 1
      // 2a: invokevirtual com/l7tech/gateway/common/task/ScheduledTask.getUserId ()Ljava/lang/String;
      // 2d: ifnull 52
      // 30: goto 37
      // 33: invokestatic com/l7tech/server/task/ScheduledTaskAdminImpl.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 36: athrow
      // 37: aload 0
      // 38: getstatic com/l7tech/objectmodel/EntityType.USER Lcom/l7tech/objectmodel/EntityType;
      // 3b: getstatic com/l7tech/gateway/common/security/rbac/OperationType.UPDATE Lcom/l7tech/gateway/common/security/rbac/OperationType;
      // 3e: invokevirtual com/l7tech/server/task/ScheduledTaskAdminImpl.a (Lcom/l7tech/objectmodel/EntityType;Lcom/l7tech/gateway/common/security/rbac/OperationType;)V
      // 41: aload 0
      // 42: getstatic com/l7tech/objectmodel/EntityType.USER Lcom/l7tech/objectmodel/EntityType;
      // 45: getstatic com/l7tech/gateway/common/security/rbac/OperationType.CREATE Lcom/l7tech/gateway/common/security/rbac/OperationType;
      // 48: invokevirtual com/l7tech/server/task/ScheduledTaskAdminImpl.a (Lcom/l7tech/objectmodel/EntityType;Lcom/l7tech/gateway/common/security/rbac/OperationType;)V
      // 4b: goto 52
      // 4e: invokestatic com/l7tech/server/task/ScheduledTaskAdminImpl.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 51: athrow
      // 52: goto 76
      // 55: astore 3
      // 56: iload 2
      // 57: ifeq 6a
      // 5a: new com/l7tech/objectmodel/SaveException
      // 5d: dup
      // 5e: aload 3
      // 5f: invokestatic com/l7tech/util/ExceptionUtils.getDebugException (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 62: invokespecial com/l7tech/objectmodel/SaveException.<init> (Ljava/lang/Throwable;)V
      // 65: athrow
      // 66: invokestatic com/l7tech/server/task/ScheduledTaskAdminImpl.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 69: athrow
      // 6a: new com/l7tech/objectmodel/UpdateException
      // 6d: dup
      // 6e: aload 3
      // 6f: invokestatic com/l7tech/util/ExceptionUtils.getDebugException (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 72: invokespecial com/l7tech/objectmodel/UpdateException.<init> (Ljava/lang/Throwable;)V
      // 75: athrow
      // 76: iload 2
      // 77: ifeq 89
      // 7a: aload 0
      // 7b: getfield com/l7tech/server/task/ScheduledTaskAdminImpl.scheduledTaskManager Lcom/l7tech/server/task/ScheduledTaskManager;
      // 7e: aload 1
      // 7f: invokeinterface com/l7tech/server/task/ScheduledTaskManager.save (Lcom/l7tech/objectmodel/PersistentEntity;)Lcom/l7tech/objectmodel/Goid; 2
      // 84: areturn
      // 85: invokestatic com/l7tech/server/task/ScheduledTaskAdminImpl.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 88: athrow
      // 89: aload 0
      // 8a: getfield com/l7tech/server/task/ScheduledTaskAdminImpl.scheduledTaskManager Lcom/l7tech/server/task/ScheduledTaskManager;
      // 8d: aload 1
      // 8e: invokeinterface com/l7tech/server/task/ScheduledTaskManager.update (Lcom/l7tech/objectmodel/PersistentEntity;)V 2
      // 93: aload 1
      // 94: invokevirtual com/l7tech/gateway/common/task/ScheduledTask.getGoid ()Lcom/l7tech/objectmodel/Goid;
      // 97: areturn
      // try (19 -> 33): 34 com/l7tech/gateway/common/security/rbac/PermissionDeniedException
      // try (16 -> 22): 23 com/l7tech/gateway/common/security/rbac/PermissionDeniedException
      // try (3 -> 12): 12 com/l7tech/gateway/common/security/rbac/PermissionDeniedException
      // try (0 -> 7): 8 com/l7tech/gateway/common/security/rbac/PermissionDeniedException
      // try (16 -> 36): 37 com/l7tech/gateway/common/security/rbac/PermissionDeniedException
      // try (38 -> 46): 46 com/l7tech/gateway/common/security/rbac/PermissionDeniedException
      // try (54 -> 61): 61 com/l7tech/gateway/common/security/rbac/PermissionDeniedException
   }

   private void a(@NotNull EntityType var1, @NotNull OperationType var2) throws PermissionDeniedException {
      try {
         if (var1 == null) {
            a(0);
         }
      } catch (FindException var7) {
         throw a(var7);
      }

      try {
         if (var2 == null) {
            a(1);
         }
      } catch (FindException var8) {
         throw a(var8);
      }

      User var3 = JaasUtils.getCurrentUser();

      try {
         try {
            if (!this.rbacServices.isPermittedForAnyEntityOfType(var3, var2, var1)) {
               throw new PermissionDeniedException(var2, var1);
            }
         } catch (PermissionDeniedException var5) {
            throw a(var5);
         }
      } catch (FindException var6) {
         throw new PermissionDeniedException(var2, var1, var6.getMessage());
      }
   }

   public void deleteScheduledTask(ScheduledTask var1) throws DeleteException {
      this.scheduledTaskManager.delete(var1);
   }

   private static Exception a(Exception var0) {
      return var0;
   }

   static {
      String[] var5 = new String[5];
      int var3 = 0;
      String var2 = "oi'-b$'|X.6k,'mm/>Xz,1k =m(-+te\u0013Wg?\ns)?9x*6g(6mm9d!` >($\"&` 7-8dk0 m(%+re1|(%1j)\rvx.6g1:vf\u001f=v ";
      int var4 = "oi'-b$'|X.6k,'mm/>Xz,1k =m(-+te\u0013Wg?\ns)?9x*6g(6mm9d!` >($\"&` 7-8dk0 m(%+re1|(%1j)\rvx.6g1:vf\u001f=v ".length();
      char var1 = 17;
      int var7 = -1;

      label24:
      while (true) {
         byte var10000 = 62;
         String var10001 = var2.substring(++var7, var7 + var1);
         byte var10002 = -1;

         while (true) {
            String var8 = a(var10000, a(var10001));
            switch (var10002) {
               case 0:
                  var5[var3++] = var8;
                  if ((var7 += var1) >= var4) {
                     a = var5;
                     return;
                  }

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

                  var2 = "^C\u0002ONV\u0003XO\u0007OQ\u0004\u0005KI\u001dOV\u0000\u0004V\u0003<\u0003J\u0004\u0013H@\n\u0004v\u0000\u0004Vm\u000b\rK\u000f>P\\\u0003\nXB\u001b\tV\u0018#D\\\n";
                  var4 = "^C\u0002ONV\u0003XO\u0007OQ\u0004\u0005KI\u001dOV\u0000\u0004V\u0003<\u0003J\u0004\u0013H@\n\u0004v\u0000\u0004Vm\u000b\rK\u000f>P\\\u0003\nXB\u001b\tV\u0018#D\\\n"
                     .length();
                  var1 = '-';
                  var7 = -1;
            }

            var10000 = 26;
            var10001 = var2.substring(++var7, var7 + var1);
            var10002 = 0;
         }
      }
   }

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

      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 -> 39;
            case 1 -> 54;
            case 2 -> 117;
            case 3 -> 122;
            case 4 -> 56;
            case 5 -> 123;
            default -> 109;
         });
      }

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