/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.security.rbac.OperationType
 *  com.l7tech.gateway.common.security.rbac.PermissionDeniedException
 *  com.l7tech.gateway.common.task.ScheduledTask
 *  com.l7tech.gateway.common.task.ScheduledTaskAdmin
 *  com.l7tech.identity.User
 *  com.l7tech.objectmodel.DeleteException
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.PersistentEntity
 *  com.l7tech.objectmodel.SaveException
 *  com.l7tech.objectmodel.UpdateException
 *  com.l7tech.util.ExceptionUtils
 *  jakarta.inject.Inject
 *  org.jetbrains.annotations.NotNull
 */
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.PersistentEntity;
import com.l7tech.objectmodel.SaveException;
import com.l7tech.objectmodel.UpdateException;
import com.l7tech.server.security.rbac.RbacServices;
import com.l7tech.server.task.ScheduledTaskManager;
import com.l7tech.server.util.JaasUtils;
import com.l7tech.util.ExceptionUtils;
import jakarta.inject.Inject;
import java.util.Collection;
import org.jetbrains.annotations.NotNull;

/*
 * Exception performing whole class analysis ignored.
 */
public class ScheduledTaskAdminImpl
implements ScheduledTaskAdmin {
    @Inject
    private ScheduledTaskManager scheduledTaskManager;
    @Inject
    private RbacServices rbacServices;
    private static final String[] a;

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

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

    /*
     * Unable to fully structure code
     */
    public Goid saveScheduledTask(ScheduledTask var1_1) throws UpdateException, SaveException {
        block18: {
            block17: {
                block16: {
                    if (var1_1.getGoid() == null) ** GOTO lbl8
                    try {
                        block19: {
                            if (!Goid.isDefault((Goid)var1_1.getGoid())) break block16;
                            break block19;
                            catch (PermissionDeniedException v0) {
                                throw ScheduledTaskAdminImpl.a((Exception)v0);
                            }
                        }
                        v1 = true;
                        break block17;
                    }
                    catch (PermissionDeniedException v2) {
                        throw ScheduledTaskAdminImpl.a((Exception)v2);
                    }
                }
                v1 = false;
            }
            var2_2 = v1;
            try {
                if (var1_1.getIdProviderGoid() != null) ** GOTO lbl25
                try {
                    block20: {
                        if (var1_1.getUserId() == null) break block18;
                        break block20;
                        catch (PermissionDeniedException v3) {
                            throw ScheduledTaskAdminImpl.a((Exception)v3);
                        }
                    }
                    this.a(EntityType.USER, OperationType.UPDATE);
                    this.a(EntityType.USER, OperationType.CREATE);
                }
                catch (PermissionDeniedException v4) {
                    throw ScheduledTaskAdminImpl.a((Exception)v4);
                }
            }
            catch (PermissionDeniedException var3_3) {
                try {
                    if (var2_2) {
                        throw new SaveException(ExceptionUtils.getDebugException((Throwable)var3_3));
                    }
                }
                catch (PermissionDeniedException v5) {
                    throw ScheduledTaskAdminImpl.a((Exception)v5);
                }
                throw new UpdateException(ExceptionUtils.getDebugException((Throwable)var3_3));
            }
        }
        try {
            if (var2_2) {
                return this.scheduledTaskManager.save((PersistentEntity)var1_1);
            }
        }
        catch (PermissionDeniedException v6) {
            throw ScheduledTaskAdminImpl.a((Exception)v6);
        }
        this.scheduledTaskManager.update((PersistentEntity)var1_1);
        return var1_1.getGoid();
    }

    private void a(@NotNull EntityType entityType, @NotNull OperationType operationType) throws PermissionDeniedException {
        try {
            if (entityType == null) {
                ScheduledTaskAdminImpl.a(0);
            }
        }
        catch (FindException findException) {
            throw ScheduledTaskAdminImpl.a((Exception)((Object)findException));
        }
        try {
            if (operationType == null) {
                ScheduledTaskAdminImpl.a(1);
            }
        }
        catch (FindException findException) {
            throw ScheduledTaskAdminImpl.a((Exception)((Object)findException));
        }
        User user = JaasUtils.getCurrentUser();
        try {
            try {
                if (!this.rbacServices.isPermittedForAnyEntityOfType(user, operationType, entityType)) {
                    throw new PermissionDeniedException(operationType, entityType);
                }
            }
            catch (PermissionDeniedException permissionDeniedException) {
                throw ScheduledTaskAdminImpl.a((Exception)((Object)permissionDeniedException));
            }
        }
        catch (FindException findException) {
            throw new PermissionDeniedException(operationType, entityType, findException.getMessage());
        }
    }

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

    /*
     * Exception decompiling
     */
    private static /* synthetic */ void a(int var0) {
        /*
         * This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
         * 
         * org.benf.cfr.reader.util.ConfusedCFRException: Tried to end blocks [0[TRYBLOCK]], but top level block is 1[SWITCH]
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.processEndingBlocks(Op04StructuredStatement.java:435)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:484)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op03SimpleStatement.createInitialStructuredBlock(Op03SimpleStatement.java:736)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:850)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:278)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:201)
         *     at org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:94)
         *     at org.benf.cfr.reader.entities.Method.analyse(Method.java:531)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:1050)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:942)
         *     at org.benf.cfr.reader.Driver.doJarVersionTypes(Driver.java:257)
         *     at org.benf.cfr.reader.Driver.doJar(Driver.java:139)
         *     at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:76)
         *     at org.benf.cfr.reader.Main.main(Main.java:54)
         */
        throw new IllegalStateException("Decompilation failed");
    }

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[5];
                var3_1 = 0;
                var2_2 = "oi'-b$'|X.6k,'mm/>Xz,1k =m(-+te\u0013Wg?\ns)?9x*6g(6mm9d!` >($\"&` 7-8dk0 m(%+re1|(%1j)\rvx.6g1:vf\u001f=v ";
                var4_3 = "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();
                var1_4 = 17;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 62;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = ScheduledTaskAdminImpl.a(v0, ScheduledTaskAdminImpl.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "^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_3 = "^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_4 = 45;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 26;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = ScheduledTaskAdminImpl.a(v0, ScheduledTaskAdminImpl.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        ScheduledTaskAdminImpl.a = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x6D);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 39;
                    case 1 -> 54;
                    case 2 -> 117;
                    case 3 -> 122;
                    case 4 -> 56;
                    case 5 -> 123;
                    default -> 109;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

