/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.RequestId
 *  com.l7tech.message.Message
 *  com.l7tech.util.TimeSource
 *  org.jetbrains.annotations.NotNull
 *  org.jetbrains.annotations.Nullable
 */
package com.l7tech.server.message;

import com.l7tech.gateway.common.RequestId;
import com.l7tech.message.Message;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.message.RoutingMetricsAwareChildPolicyEnforcementContext;
import com.l7tech.server.message.b;
import com.l7tech.server.message.e;
import com.l7tech.server.message.h;
import com.l7tech.util.TimeSource;
import java.util.concurrent.Callable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/*
 * Exception performing whole class analysis ignored.
 */
public class PolicyEnforcementContextFactory {
    @NotNull
    private static TimeSource a;
    public static final ThreadLocal<PolicyEnforcementContext> instanceHolder;
    public static final ThreadLocal<PolicyEnforcementContext> childInstanceHolder;
    private static final String[] b;

    public static PolicyEnforcementContext createPolicyEnforcementContext(@Nullable Message message, @Nullable Message message2) {
        return PolicyEnforcementContextFactory.createPolicyEnforcementContext(message, message2, true);
    }

    public static PolicyEnforcementContext createPolicyEnforcementContext(@Nullable Message message, @Nullable Message message2, boolean bl2) {
        PolicyEnforcementContext policyEnforcementContext = PolicyEnforcementContextFactory.createUnregisteredPolicyEnforcementContext(message, message2, bl2);
        return PolicyEnforcementContextFactory.a(policyEnforcementContext, instanceHolder);
    }

    public static PolicyEnforcementContext createUnregisteredPolicyEnforcementContext(@Nullable Message message, @Nullable Message message2, boolean bl2) {
        b b10 = new b(message, message2, a);
        b10.setReplyExpected(bl2);
        return b10;
    }

    public static PolicyEnforcementContext createUnregisteredPolicyEnforcementContext(@Nullable Message message, @Nullable Message message2, @NotNull RequestId requestId, boolean bl2) {
        try {
            if (requestId == null) {
                PolicyEnforcementContextFactory.a(0);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyEnforcementContextFactory.a(illegalArgumentException);
        }
        b b10 = new b(message, message2, a, requestId);
        b10.setReplyExpected(bl2);
        return b10;
    }

    public static PolicyEnforcementContext createPolicyEnforcementContext(PolicyEnforcementContext policyEnforcementContext) {
        return PolicyEnforcementContextFactory.a(PolicyEnforcementContextFactory.createUnregisteredPolicyEnforcementContext(policyEnforcementContext), childInstanceHolder);
    }

    public static PolicyEnforcementContext createPolicyEnforcementContext(PolicyEnforcementContext policyEnforcementContext, boolean bl2) {
        return PolicyEnforcementContextFactory.a(PolicyEnforcementContextFactory.createUnregisteredPolicyEnforcementContext(policyEnforcementContext, bl2), childInstanceHolder);
    }

    public static PolicyEnforcementContext createUnregisteredPolicyEnforcementContext(PolicyEnforcementContext policyEnforcementContext, boolean bl2) {
        h h2;
        b b10 = new b(null, null, a, policyEnforcementContext.getRequestId());
        try {
            h2 = bl2 ? new RoutingMetricsAwareChildPolicyEnforcementContext(policyEnforcementContext, b10) : new h(policyEnforcementContext, b10);
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyEnforcementContextFactory.a(illegalArgumentException);
        }
        return h2;
    }

    public static PolicyEnforcementContext createUnregisteredPolicyEnforcementContext(PolicyEnforcementContext policyEnforcementContext) {
        return new h(policyEnforcementContext, new b(null, null, a, policyEnforcementContext.getRequestId()));
    }

    public static PolicyEnforcementContext getCurrent() {
        PolicyEnforcementContext policyEnforcementContext = childInstanceHolder.get();
        if (policyEnforcementContext == null) {
            policyEnforcementContext = instanceHolder.get();
        }
        return policyEnforcementContext;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public static <T> T doWithCurrentContext(PolicyEnforcementContext policyEnforcementContext, Callable<T> callable) throws Exception {
        PolicyEnforcementContext policyEnforcementContext2 = childInstanceHolder.get();
        try {
            childInstanceHolder.set(policyEnforcementContext);
            T t2 = callable.call();
            return t2;
        }
        finally {
            childInstanceHolder.set(policyEnforcementContext2);
        }
    }

    public static void setTimeSource(@NotNull TimeSource timeSource) {
        try {
            if (timeSource == null) {
                PolicyEnforcementContextFactory.a(1);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyEnforcementContextFactory.a(illegalArgumentException);
        }
        a = timeSource;
    }

    private static PolicyEnforcementContext a(PolicyEnforcementContext policyEnforcementContext, ThreadLocal<PolicyEnforcementContext> threadLocal) {
        threadLocal.set(policyEnforcementContext);
        policyEnforcementContext.runOnClose(new e(threadLocal));
        return policyEnforcementContext;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[6];
                var3_1 = 0;
                var2_2 = "\\\u001bm\u001dLh\u001eZ\u0017h\u001dS:\u0018I\u0011r\u001dM:\u0019L\u0015gW\u000f\u000f\u0005S\u001dcKe1\fP\u0006cWM:\u0004K7o\\T:\u0012K2aQT0\u0018F*\\\u0006eST:?Q\u0006eUI,\u001eZ\u0006eVp0\u0006V\u0017ywN9\u0005M\u0017e_E1\u001e|\u001bnFE'\u001e\rL\u0011tfI2\u000fl\u001bu@C:>~\u0006gGM:\u0004KTf]R\u007f*q\u001bt|U3\u0006\u001f\u0004a@A2\u000fK\u0011r\u0012\u0007z\u0019\u0018ToT\u0000z\u0019\u0011Qs\u0012M*\u0019KTn]T\u007f\bZTnGL3";
                var4_3 = "\\\u001bm\u001dLh\u001eZ\u0017h\u001dS:\u0018I\u0011r\u001dM:\u0019L\u0015gW\u000f\u000f\u0005S\u001dcKe1\fP\u0006cWM:\u0004K7o\\T:\u0012K2aQT0\u0018F*\\\u0006eST:?Q\u0006eUI,\u001eZ\u0006eVp0\u0006V\u0017ywN9\u0005M\u0017e_E1\u001e|\u001bnFE'\u001e\rL\u0011tfI2\u000fl\u001bu@C:>~\u0006gGM:\u0004KTf]R\u007f*q\u001bt|U3\u0006\u001f\u0004a@A2\u000fK\u0011r\u0012\u0007z\u0019\u0018ToT\u0000z\u0019\u0011Qs\u0012M*\u0019KTn]T\u007f\bZTnGL3".length();
                var1_4 = 57;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = PolicyEnforcementContextFactory.a(v0, PolicyEnforcementContextFactory.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\n\\,\u00162q^\fV$\t\fP0\u0006\u0004m_7Q";
                    var4_3 = "\n\\,\u00162q^\fV$\t\fP0\u0006\u0004m_7Q".length();
                    var1_4 = 10;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 47;
                        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++] = PolicyEnforcementContextFactory.a(v0, PolicyEnforcementContextFactory.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;
            }
        }
        PolicyEnforcementContextFactory.b = var5;
        PolicyEnforcementContextFactory.a = new TimeSource();
        PolicyEnforcementContextFactory.instanceHolder = new ThreadLocal<T>();
        PolicyEnforcementContextFactory.childInstanceHolder = new ThreadLocal<T>();
    }

    /*
     * 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 2[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 IllegalArgumentException a(IllegalArgumentException illegalArgumentException) {
        return illegalArgumentException;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 4);
        }
        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 -> 81;
                    case 1 -> 26;
                    case 2 -> 110;
                    case 3 -> 92;
                    case 4 -> 78;
                    case 5 -> 49;
                    default -> 4;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

