/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.DeleteException
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.EntityHeader
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.policy.CustomKeyValueStore
 *  com.l7tech.policy.assertion.ext.store.KeyValueStoreChangeEventListener
 *  com.l7tech.policy.assertion.ext.store.KeyValueStoreChangeEventListener$Callback
 *  com.l7tech.policy.assertion.ext.store.KeyValueStoreChangeEventListener$Event
 *  com.l7tech.policy.assertion.ext.store.KeyValueStoreChangeEventListener$Operation
 *  com.l7tech.policy.assertion.ext.store.KeyValueStoreListener
 *  org.jetbrains.annotations.NotNull
 *  org.springframework.context.ApplicationEvent
 *  org.springframework.orm.hibernate5.HibernateCallback
 */
package com.l7tech.server.store;

import com.l7tech.objectmodel.DeleteException;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.policy.CustomKeyValueStore;
import com.l7tech.policy.assertion.ext.store.KeyValueStoreChangeEventListener;
import com.l7tech.policy.assertion.ext.store.KeyValueStoreListener;
import com.l7tech.server.HibernateEntityManager;
import com.l7tech.server.event.EntityInvalidationEvent;
import com.l7tech.server.policy.CustomKeyValueStoreManager;
import com.l7tech.server.store.a;
import com.l7tech.server.store.b;
import com.l7tech.server.store.c;
import com.l7tech.server.store.d;
import com.l7tech.server.util.ApplicationEventProxy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.ApplicationEvent;
import org.springframework.orm.hibernate5.HibernateCallback;

/*
 * Exception performing whole class analysis ignored.
 */
public class CustomKeyValueStoreManagerImpl
extends HibernateEntityManager<CustomKeyValueStore, EntityHeader>
implements CustomKeyValueStoreManager {
    private final Map<Goid, String> m = new ConcurrentHashMap<Goid, String>();
    private final a n = new a(this);
    private static final String[] o;

    public CustomKeyValueStoreManagerImpl(ApplicationEventProxy applicationEventProxy) {
        applicationEventProxy.addApplicationListener(new c(this));
    }

    public Class<? extends Entity> getImpClass() {
        return CustomKeyValueStore.class;
    }

    @Override
    @NotNull
    public Collection<CustomKeyValueStore> findByKeyPrefix(@NotNull String string) throws FindException {
        Collection collection;
        try {
            if (string == null) {
                CustomKeyValueStoreManagerImpl.b(0);
            }
        }
        catch (Exception exception) {
            throw CustomKeyValueStoreManagerImpl.a(exception);
        }
        try {
            collection = Objects.requireNonNull((Collection)this.getHibernateTemplate().execute((HibernateCallback)new d(this, string)));
        }
        catch (Exception exception) {
            throw new FindException(o[5] + string, (Throwable)exception);
        }
        if (collection == null) {
            CustomKeyValueStoreManagerImpl.b(1);
        }
        return collection;
    }

    @Override
    public CustomKeyValueStore findByUniqueName(String string) throws FindException {
        try {
            if (string == null) {
                return null;
            }
        }
        catch (FindException findException) {
            throw CustomKeyValueStoreManagerImpl.a((Exception)((Object)findException));
        }
        return (CustomKeyValueStore)super.findByUniqueName(string);
    }

    @Override
    public void deleteByKey(@NotNull String string) throws DeleteException {
        try {
            if (string == null) {
                CustomKeyValueStoreManagerImpl.b(2);
            }
        }
        catch (FindException findException) {
            throw CustomKeyValueStoreManagerImpl.a((Exception)((Object)findException));
        }
        try {
            CustomKeyValueStore customKeyValueStore = this.findByUniqueName(string);
            try {
                if (customKeyValueStore != null) {
                    this.delete(customKeyValueStore);
                }
            }
            catch (FindException findException) {
                throw CustomKeyValueStoreManagerImpl.a((Exception)((Object)findException));
            }
        }
        catch (FindException findException) {
            throw new DeleteException(o[7] + string, (Throwable)findException);
        }
    }

    public <T extends KeyValueStoreListener> T getListener(Class<T> clazz) {
        try {
            if (KeyValueStoreChangeEventListener.class.equals(clazz)) {
                return (T)((Object)this.n);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw CustomKeyValueStoreManagerImpl.a(illegalArgumentException);
        }
        return null;
    }

    @Override
    public void delete(CustomKeyValueStore customKeyValueStore) throws DeleteException {
        super.delete(customKeyValueStore);
        this.m.put(customKeyValueStore.getGoid(), customKeyValueStore.getName());
    }

    /*
     * WARNING - void declaration
     */
    private void a(ApplicationEvent applicationEvent) {
        Object object;
        try {
            if (!(applicationEvent instanceof EntityInvalidationEvent)) {
                return;
            }
        }
        catch (FindException findException) {
            throw CustomKeyValueStoreManagerImpl.a((Exception)((Object)findException));
        }
        EntityInvalidationEvent entityInvalidationEvent = (EntityInvalidationEvent)applicationEvent;
        try {
            if (!CustomKeyValueStore.class.equals(entityInvalidationEvent.getEntityClass())) {
                return;
            }
        }
        catch (FindException findException) {
            throw CustomKeyValueStoreManagerImpl.a((Exception)((Object)findException));
        }
        Goid[] goidArray = entityInvalidationEvent.getEntityIds();
        char[] cArray = entityInvalidationEvent.getEntityOperations();
        ArrayList<b> arrayList = new ArrayList<b>(goidArray.length);
        for (int i2 = 0; i2 < goidArray.length; ++i2) {
            Object var7_9 = null;
            char c10 = cArray[i2];
            Goid goid = goidArray[i2];
            if (c10 == 'C') {
                object = KeyValueStoreChangeEventListener.Operation.CREATE;
                try {
                    var11_26 = (CustomKeyValueStore)this.findByPrimaryKey(goid);
                    if (var11_26 != null) {
                        String string = var11_26.getName();
                    }
                }
                catch (FindException findException) {
                    Object var7_12 = null;
                }
            } else if (c10 == 'U') {
                object = KeyValueStoreChangeEventListener.Operation.UPDATE;
                try {
                    var11_26 = (CustomKeyValueStore)this.findByPrimaryKey(goid);
                    if (var11_26 != null) {
                        String string = var11_26.getName();
                    }
                }
                catch (FindException findException) {
                    Object var7_15 = null;
                }
            } else if (c10 == 'D') {
                object = KeyValueStoreChangeEventListener.Operation.DELETE;
                String string = this.m.remove(goid);
            } else {
                throw new IllegalArgumentException(o[8] + c10);
            }
            try {
                void object2;
                if (object2 == null) continue;
                arrayList.add(new b(this, (String)object2, (KeyValueStoreChangeEventListener.Operation)object));
                continue;
            }
            catch (FindException findException) {
                throw CustomKeyValueStoreManagerImpl.a((Exception)((Object)findException));
            }
        }
        for (Map.Entry<String, Set<KeyValueStoreChangeEventListener.Callback>> entry : this.n.a().entrySet()) {
            object = new ArrayList(arrayList.size());
            for (KeyValueStoreChangeEventListener.Event event : arrayList) {
                try {
                    if (!event.getKey().startsWith(entry.getKey())) continue;
                    object.add(event);
                }
                catch (FindException findException) {
                    throw CustomKeyValueStoreManagerImpl.a((Exception)((Object)findException));
                }
            }
            for (KeyValueStoreChangeEventListener.Callback callback : entry.getValue()) {
                callback.onEvent((List)object);
            }
        }
    }

    /*
     * Exception decompiling
     */
    private static /* synthetic */ void b(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 6[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[12];
                var3_1 = 0;
                var2_2 = "N2h\u0013\u0002 4H>m\u0013\u001dr2[8w\u0013\u001dc/_8*\u007f\u001bd4B0NY\u0017A!A(`o\u001ax2H\u0010dR\u000fp%_\u0014hL\u0002\u000fK4kX,n\u000bH$UN\u000bq)U\u000fK4kX,n\u000bH$UN\u000bq)U6N2h\u0013\u0002 4H>m\u0013\u001dr2[8w\u0013\u001dc/_8*\u007f\u001bd4B0NY\u0017A!A(`o\u001ax2H\u0010dR\u000fp%_\u0014hL\u0002\u000bI8iY\u001ar\u0002T\u0016`E!x3d^\u0002r`Y2%Z\u0007y$\r(vU\u0000p`F8|\u001c\u001ee%K4}\u0006N\u0003F8|\u001cx3d^\u0002r`Y2%X\u000b{%Y8%I\u001d~.J}nY\u0017-`\u0016x3`D\u001er#Y8a\u001c\u0001g%_<qU\u0001yz\r*m\u0013jH b,A}hY\u001a\u007f/I} O@23\r0pO\u001a7.B)%N\u000bc5_3%R\u001b{,";
                var4_3 = "N2h\u0013\u0002 4H>m\u0013\u001dr2[8w\u0013\u001dc/_8*\u007f\u001bd4B0NY\u0017A!A(`o\u001ax2H\u0010dR\u000fp%_\u0014hL\u0002\u000fK4kX,n\u000bH$UN\u000bq)U\u000fK4kX,n\u000bH$UN\u000bq)U6N2h\u0013\u0002 4H>m\u0013\u001dr2[8w\u0013\u001dc/_8*\u007f\u001bd4B0NY\u0017A!A(`o\u001ax2H\u0010dR\u000fp%_\u0014hL\u0002\u000bI8iY\u001ar\u0002T\u0016`E!x3d^\u0002r`Y2%Z\u0007y$\r(vU\u0000p`F8|\u001c\u001ee%K4}\u0006N\u0003F8|\u001cx3d^\u0002r`Y2%X\u000b{%Y8%I\u001d~.J}nY\u0017-`\u0016x3`D\u001er#Y8a\u001c\u0001g%_<qU\u0001yz\r*m\u0013jH b,A}hY\u001a\u007f/I} O@23\r0pO\u001a7.B)%N\u000bc5_3%R\u001b{,".length();
                var1_4 = 54;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = CustomKeyValueStoreManagerImpl.b(v0, CustomKeyValueStoreManagerImpl.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "Z$`p\u0000n:X9>p3~U\u001fn2Ea\u007fO\u0000+\u001c\u007f.mn\u0007g0\u00111xR\u0013f9E$k\u0000U./\u0016avFR./\u001fdj\u0000\u001f~/EawO\u0006+>TawU\u001eg";
                    var4_3 = "Z$`p\u0000n:X9>p3~U\u001fn2Ea\u007fO\u0000+\u001c\u007f.mn\u0007g0\u00111xR\u0013f9E$k\u0000U./\u0016avFR./\u001fdj\u0000\u001f~/EawO\u0006+>TawU\u001eg".length();
                    var1_4 = 9;
                    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++] = CustomKeyValueStoreManagerImpl.b(v0, CustomKeyValueStoreManagerImpl.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;
            }
        }
        CustomKeyValueStoreManagerImpl.o = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x46);
        }
        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 -> 43;
                    case 1 -> 91;
                    case 2 -> 3;
                    case 3 -> 58;
                    case 4 -> 104;
                    case 5 -> 17;
                    default -> 70;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

