/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.github.benmanes.caffeine.cache.Cache
 *  com.github.benmanes.caffeine.cache.Caffeine
 *  com.l7tech.objectmodel.EntityHeader
 *  com.l7tech.objectmodel.EntityManager
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.GuidEntity
 *  com.l7tech.objectmodel.NamedEntity
 *  com.l7tech.objectmodel.PersistentEntity
 *  com.l7tech.objectmodel.SimpleGuidEntityResolver
 *  com.l7tech.util.ConfigFactory
 *  com.l7tech.util.ConfigFactory$ConfigurationListener
 *  org.jetbrains.annotations.NotNull
 *  org.springframework.context.ApplicationEvent
 */
package com.l7tech.server.policy;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.EntityManager;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.GuidEntity;
import com.l7tech.objectmodel.NamedEntity;
import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.objectmodel.SimpleGuidEntityResolver;
import com.l7tech.server.ServerConfig;
import com.l7tech.server.event.EntityInvalidationEvent;
import com.l7tech.server.policy.c;
import com.l7tech.server.policy.d;
import com.l7tech.server.util.ApplicationEventProxy;
import com.l7tech.util.ConfigFactory;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.ApplicationEvent;

/*
 * Exception performing whole class analysis ignored.
 */
public class CacheableGuidEntityResolver<T1 extends GuidEntity>
extends SimpleGuidEntityResolver<T1> {
    private static final Logger a;
    private static final String b;
    private static final int c = 100;
    private static final String d;
    private static final int e = 300000;
    private final ServerConfig f;
    private Cache<String, d> g;
    private Cache<String, d> h;
    private static final String i;
    private static final String[] j;

    public CacheableGuidEntityResolver(@NotNull EntityManager<? extends PersistentEntity, ? extends EntityHeader> entityManager, ApplicationEventProxy applicationEventProxy, @NotNull ServerConfig serverConfig) {
        if (entityManager == null) {
            CacheableGuidEntityResolver.a(0);
        }
        if (serverConfig == null) {
            CacheableGuidEntityResolver.a(1);
        }
        super(entityManager);
        this.f = serverConfig;
        applicationEventProxy.addApplicationListener(applicationEvent -> {
            EntityInvalidationEvent entityInvalidationEvent = this.a(applicationEvent);
            try {
                if (entityInvalidationEvent == null) {
                    return;
                }
            }
            catch (NullPointerException nullPointerException) {
                throw CacheableGuidEntityResolver.a(nullPointerException);
            }
            Goid[] goidArray = entityInvalidationEvent.getEntityIds();
            int n2 = 0;
            while (true) {
                block8: {
                    try {
                        try {
                            if (n2 >= goidArray.length) break;
                            if (!CacheableGuidEntityResolver.a(entityInvalidationEvent.getEntityOperations()[n2])) break block8;
                        }
                        catch (NullPointerException nullPointerException) {
                            throw CacheableGuidEntityResolver.a(nullPointerException);
                        }
                        this.a(goidArray[n2]);
                    }
                    catch (NullPointerException nullPointerException) {
                        throw CacheableGuidEntityResolver.a(nullPointerException);
                    }
                }
                ++n2;
            }
        });
        this.a();
    }

    private void a() {
        this.c();
        this.b();
    }

    private void b() {
        ConfigFactory.addListener((ConfigFactory.ConfigurationListener)new c(this), (String[])new String[0]);
    }

    private void c() {
        String[] stringArray = j;
        int n2 = this.f.getIntProperty(stringArray[1], 100);
        long l2 = this.f.getTimeUnitProperty(stringArray[4], 300000L);
        a.log(Level.INFO, stringArray[8], new Object[]{this.getEntityManager().getEntityType(), l2, n2});
        this.g = Caffeine.newBuilder().expireAfterAccess(l2, TimeUnit.MILLISECONDS).maximumSize((long)n2).build();
        this.h = Caffeine.newBuilder().expireAfterAccess(l2, TimeUnit.MILLISECONDS).maximumSize((long)n2).build();
    }

    public String findGuidByName(String string) {
        d d10 = (d)this.g.get((Object)string, string2 -> {
            a.log(Level.FINE, j[10], new Object[]{this.getEntityManager().getEntityType(), string});
            return com.l7tech.server.policy.d.newInstance(string, super.findGuidByName(string));
        });
        try {
            if (d10 == null) {
                return null;
            }
        }
        catch (NullPointerException nullPointerException) {
            throw CacheableGuidEntityResolver.a(nullPointerException);
        }
        this.h.put((Object)d10.getGuid(), (Object)d10);
        return d10.getGuid();
    }

    public String findNameByGuid(String string) {
        d d10 = (d)this.h.get((Object)string, string2 -> {
            a.log(Level.FINE, j[12], new Object[]{this.getEntityManager().getEntityType(), string});
            return com.l7tech.server.policy.d.newInstance(super.findNameByGuid(string), string);
        });
        try {
            if (d10 == null) {
                return null;
            }
        }
        catch (NullPointerException nullPointerException) {
            throw CacheableGuidEntityResolver.a(nullPointerException);
        }
        this.g.put((Object)d10.getName(), (Object)d10);
        return d10.getName();
    }

    protected boolean isInterestedEntityEvent(EntityInvalidationEvent entityInvalidationEvent) {
        return GuidEntity.class.isAssignableFrom(entityInvalidationEvent.getEntityClass());
    }

    protected void notifyUpdate(T1 T1) throws NullPointerException {
        if (T1 instanceof NamedEntity) {
            NamedEntity namedEntity = (NamedEntity)T1;
            a.log(Level.FINE, j[12], new Object[]{this.getEntityManager().getEntityType(), namedEntity.getName()});
            d d10 = com.l7tech.server.policy.d.newInstance(namedEntity.getName(), T1.getGuid());
            try {
                if (d10 != null) {
                    this.g.put((Object)d10.getName(), (Object)d10);
                    this.h.put((Object)d10.getGuid(), (Object)d10);
                }
            }
            catch (NullPointerException nullPointerException) {
                throw CacheableGuidEntityResolver.a(nullPointerException);
            }
        }
    }

    private void a(Goid goid) {
        try {
            this.notifyUpdate(this.getEntityManager().findByPrimaryKey(goid));
        }
        catch (FindException findException) {
            a.log(Level.INFO, j[7], new Object[]{this.getEntityManager().getEntityType(), goid, findException.getMessage()});
        }
    }

    private EntityInvalidationEvent a(ApplicationEvent applicationEvent) {
        if (applicationEvent instanceof EntityInvalidationEvent) {
            EntityInvalidationEvent entityInvalidationEvent = (EntityInvalidationEvent)applicationEvent;
            try {
                if (this.isInterestedEntityEvent(entityInvalidationEvent)) {
                    return entityInvalidationEvent;
                }
            }
            catch (NullPointerException nullPointerException) {
                throw CacheableGuidEntityResolver.a(nullPointerException);
            }
        }
        return null;
    }

    private static boolean a(char c10) {
        boolean bl2;
        block5: {
            block4: {
                try {
                    try {
                        if (c10 != 'C' && c10 != 'U') break block4;
                    }
                    catch (NullPointerException nullPointerException) {
                        throw CacheableGuidEntityResolver.a(nullPointerException);
                    }
                    bl2 = true;
                    break block5;
                }
                catch (NullPointerException nullPointerException) {
                    throw CacheableGuidEntityResolver.a(nullPointerException);
                }
            }
            bl2 = false;
        }
        return bl2;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[13];
                var3_1 = 0;
                var2_2 = "\u001fZU\u0018+Xx\u0011[E.\u000bEc\u0014YY\u000e@Um\u001bGY5\nZi,FQ\u0019\u001c\u001fZU\u0018+Xx\u0011[E.\u000bEc\u0014YY\u000e@Um\u001bGY/\u0007Li\f\u000bJN\n\u000bDO\u0017AZ\u0015\t\u0007\u0015NR\u001d\tS~ \u001fZU\u0018+Xx\u0011[E.\u000bEc\u0014YY\u000e@Um\u001bGY5\nZi,FQ\u0019>9][\t\u0003Sb\f\u000fZ\u0013\u001c\u0016L6@H2\u001bZ`X_]\u000e\u000f[i\fJN\\I\u0013\u007f_\u000fS\u001aN\u0013\u007fV\nO\\\u0003C\u007f\f\u000fR\u0013\u001a\u0016n\u001d\u000fR\t\u0002Z\u0006DFR\u0015\u001a\bO-AY\u0004\u001eSo\fJX\\\u000bD~\u0017]\u001c\u0019\u0000Uc\rAH\u0019\u001cShXIS\u000eNAd\u0011CY\\\u0000Yx\u0011IE\u0015\u0000Q,\fGY\\\u000bXx\u0011[E\\\u001bFh\u0019[Y\\\u0015\u0006qWT\r\u0001B\u0016wJRS*JZ\u000e\u000bEd\u0011A[\\\u001a^iXhi5*\u0016I\u0016[U\b\u0017\u0016^\u001d\\S\u0010\u0018S~Xl]\u001f\u0006S,PT\f\u0001G\u001a,\u0011KP\u0019NBe\u0015JS\t\u001a\u000bwIR\u0010\\\u0003Wt\u0011BI\u0011NEe\u0002J\u0001\u0007\\K\u001c\u001fZU\u0018+Xx\u0011[E.\u000bEc\u0014YY\u000e@Um\u001bGY/\u0007Li\u001a;N_\u0014\u0007XkX[T\u0019NSb\fFH\u0005NM<\u0005\u0000GM\u0013";
                var4_3 = "\u001fZU\u0018+Xx\u0011[E.\u000bEc\u0014YY\u000e@Um\u001bGY5\nZi,FQ\u0019\u001c\u001fZU\u0018+Xx\u0011[E.\u000bEc\u0014YY\u000e@Um\u001bGY/\u0007Li\f\u000bJN\n\u000bDO\u0017AZ\u0015\t\u0007\u0015NR\u001d\tS~ \u001fZU\u0018+Xx\u0011[E.\u000bEc\u0014YY\u000e@Um\u001bGY5\nZi,FQ\u0019>9][\t\u0003Sb\f\u000fZ\u0013\u001c\u0016L6@H2\u001bZ`X_]\u000e\u000f[i\fJN\\I\u0013\u007f_\u000fS\u001aN\u0013\u007fV\nO\\\u0003C\u007f\f\u000fR\u0013\u001a\u0016n\u001d\u000fR\t\u0002Z\u0006DFR\u0015\u001a\bO-AY\u0004\u001eSo\fJX\\\u000bD~\u0017]\u001c\u0019\u0000Uc\rAH\u0019\u001cShXIS\u000eNAd\u0011CY\\\u0000Yx\u0011IE\u0015\u0000Q,\fGY\\\u000bXx\u0011[E\\\u001bFh\u0019[Y\\\u0015\u0006qWT\r\u0001B\u0016wJRS*JZ\u000e\u000bEd\u0011A[\\\u001a^iXhi5*\u0016I\u0016[U\b\u0017\u0016^\u001d\\S\u0010\u0018S~Xl]\u001f\u0006S,PT\f\u0001G\u001a,\u0011KP\u0019NBe\u0015JS\t\u001a\u000bwIR\u0010\\\u0003Wt\u0011BI\u0011NEe\u0002J\u0001\u0007\\K\u001c\u001fZU\u0018+Xx\u0011[E.\u000bEc\u0014YY\u000e@Um\u001bGY/\u0007Li\u001a;N_\u0014\u0007XkX[T\u0019NSb\fFH\u0005NM<\u0005\u0000GM\u0013".length();
                var1_4 = 32;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = CacheableGuidEntityResolver.b(v0, CacheableGuidEntityResolver.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = ")rca03J/~fa/aL<x|a,kR#~wa\u001fe]\"xo,0ay?tj\u000b2pW>d\\+/kR<x|\u001a\t|m&5jYjif+|aP>tz7|\u007f\u000e72u\u007f!";
                    var4_3 = ")rca03J/~fa/aL<x|a,kR#~wa\u001fe]\"xo,0ay?tj\u000b2pW>d\\+/kR<x|\u001a\t|m&5jYjif+|aP>tz7|\u007f\u000e72u\u007f!".length();
                    var1_4 = 52;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 57;
                        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++] = CacheableGuidEntityResolver.b(v0, CacheableGuidEntityResolver.b(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;
            }
        }
        CacheableGuidEntityResolver.j = var5;
        CacheableGuidEntityResolver.b = CacheableGuidEntityResolver.j[9];
        CacheableGuidEntityResolver.i = CacheableGuidEntityResolver.j[12];
        CacheableGuidEntityResolver.d = CacheableGuidEntityResolver.j[0];
        CacheableGuidEntityResolver.a = Logger.getLogger(CacheableGuidEntityResolver.class.getName());
    }

    /*
     * 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 NullPointerException a(NullPointerException nullPointerException) {
        return nullPointerException;
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String b(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 -> 115;
                    case 1 -> 36;
                    case 2 -> 55;
                    case 3 -> 119;
                    case 4 -> 101;
                    case 5 -> 61;
                    default -> 7;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

