/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.policy.assertion.ext.message.CustomJsonData
 *  com.l7tech.policy.assertion.ext.message.format.CustomMessageFormat
 *  com.l7tech.policy.assertion.ext.message.format.CustomMessageFormatFactory
 *  org.jetbrains.annotations.NotNull
 */
package com.l7tech.server.custom.format;

import com.l7tech.policy.assertion.ext.message.CustomJsonData;
import com.l7tech.policy.assertion.ext.message.format.CustomMessageFormat;
import com.l7tech.policy.assertion.ext.message.format.CustomMessageFormatFactory;
import com.l7tech.server.StashManagerFactory;
import com.l7tech.server.custom.format.CustomMessageFormatFactoryImpl;
import com.l7tech.server.custom.format.CustomMessageInputStreamFormat;
import com.l7tech.server.custom.format.CustomMessageJsonFormat;
import com.l7tech.server.custom.format.CustomMessageXmlFormat;
import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Document;

/*
 * Exception performing whole class analysis ignored.
 */
public class CustomMessageFormatRegistry {
    private final Map<Class, CustomMessageFormat> a;
    private final CustomMessageFormatFactory b;
    private static final String[] c;

    public final Map<Class, CustomMessageFormat> getFormatMap() {
        return this.a;
    }

    public final CustomMessageFormatFactory getMessageFormatFactory() {
        return this.b;
    }

    public CustomMessageFormatRegistry(final @NotNull StashManagerFactory stashManagerFactory) {
        if (stashManagerFactory == null) {
            CustomMessageFormatRegistry.a(0);
        }
        this((Map<Class, CustomMessageFormat>)new HashMap<Class, CustomMessageFormat>(){
            static final long serialVersionUID = 7625612101453042151L;
            private static final String[] a;
            {
                String[] stringArray = a;
                this.put(Document.class, new CustomMessageXmlFormat(stashManagerFactory, stringArray[2], stringArray[4]));
                this.put(CustomJsonData.class, new CustomMessageJsonFormat(stashManagerFactory, stringArray[0], stringArray[5]));
                this.put(InputStream.class, new CustomMessageInputStreamFormat(stashManagerFactory, stringArray[3], stringArray[1]));
            }

            /*
             * Unable to fully structure code
             */
            static {
                block10: {
                    block9: {
                        var5 = new String[6];
                        var3_1 = 0;
                        var2_2 = "xMg%\"{pX\u001ei[ FlM\np[0Gm\\\u0004p[>Wm[\nz\u001eStqZ\u0006|\u000f\u0003jSd\u000b{pX\u001ei(\u0007@{I\u0006";
                        var4_3 = "xMg%\"{pX\u001ei[ FlM\np[0Gm\\\u0004p[>Wm[\nz\u001eStqZ\u0006|\u000f\u0003jSd\u000b{pX\u001ei(\u0007@{I\u0006".length();
                        var1_4 = 4;
                        var0_5 = -1;
lbl7:
                        // 2 sources

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

                        while (true) {
                            var5[var3_1++] = 1.a(v0, 1.a(v2));
                            if ((var0_5 += var1_4) < var4_3) {
                                var1_4 = var2_2.charAt(var0_5);
                                ** continue;
                            }
                            var2_2 = "G`Tzo?1w@tza/1pN~?\f\f-qBx.\u001aI|V\u0014\f\t7p[v7\f\u0007'p\\x=Ij\u0004l]t;X";
                            var4_3 = "G`Tzo?1w@tza/1pN~?\f\f-qBx.\u001aI|V\u0014\f\t7p[v7\f\u0007'p\\x=Ij\u0004l]t;X".length();
                            var1_4 = 25;
                            var0_5 = -1;
lbl22:
                            // 2 sources

                            while (true) {
                                v0 = 60;
                                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++] = 1.a(v0, 1.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;
                    }
                }
                1.a = var5;
            }

            private static char[] a(String string) {
                char[] cArray = string.toCharArray();
                if (cArray.length < 2) {
                    cArray = cArray;
                    cArray[0] = (char)(cArray[0] ^ 0x7E);
                }
                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 -> 63;
                            case 1 -> 19;
                            case 2 -> 37;
                            case 3 -> 102;
                            case 4 -> 16;
                            case 5 -> 118;
                            default -> 126;
                        })));
                        ++n3;
                        n4 = n4;
                    } while (n4 > n3);
                }
                return new String(cArray2).intern();
            }
        });
    }

    protected CustomMessageFormatRegistry(@NotNull Map<Class, CustomMessageFormat> map) {
        if (map == null) {
            CustomMessageFormatRegistry.a(1);
        }
        this.a = new ConcurrentHashMap<Class, CustomMessageFormat>(map);
        this.b = new CustomMessageFormatFactoryImpl(this);
    }

    public <T> void register(@NotNull Class<T> clazz, @NotNull CustomMessageFormat customMessageFormat) {
        try {
            if (clazz == null) {
                CustomMessageFormatRegistry.a(2);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw CustomMessageFormatRegistry.a(illegalArgumentException);
        }
        try {
            if (customMessageFormat == null) {
                CustomMessageFormatRegistry.a(3);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw CustomMessageFormatRegistry.a(illegalArgumentException);
        }
        this.getFormatMap().put(clazz, customMessageFormat);
    }

    public <T> CustomMessageFormat remove(@NotNull Class<T> clazz) {
        try {
            if (clazz == null) {
                CustomMessageFormatRegistry.a(4);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw CustomMessageFormatRegistry.a(illegalArgumentException);
        }
        return this.getFormatMap().remove(clazz);
    }

    public <T> CustomMessageFormat<T> get(@NotNull Class<T> clazz) {
        try {
            if (clazz == null) {
                CustomMessageFormatRegistry.a(5);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw CustomMessageFormatRegistry.a(illegalArgumentException);
        }
        return this.getFormatMap().get(clazz);
    }

    public CustomMessageFormat getForName(@NotNull String string) {
        try {
            if (string == null) {
                CustomMessageFormatRegistry.a(6);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw CustomMessageFormatRegistry.a(illegalArgumentException);
        }
        for (CustomMessageFormat customMessageFormat : this.getFormatMap().values()) {
            String string2 = customMessageFormat.getFormatName();
            try {
                try {
                    if (string2 == null || string.compareToIgnoreCase(string2) != 0) continue;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw CustomMessageFormatRegistry.a(illegalArgumentException);
                }
                return customMessageFormat;
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw CustomMessageFormatRegistry.a(illegalArgumentException);
            }
        }
        return null;
    }

    public Collection<CustomMessageFormat> getKnownFormats() {
        return Collections.unmodifiableCollection(this.getFormatMap().values());
    }

    /*
     * 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;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[12];
                var3_1 = 0;
                var2_2 = "d4J\u0010\u0010b-b<[\u0007e>L;\u001ed\u0010>B#Y#\u0012u\rwqX9\r0#M>J\u0018\n|\u000f#!_$\u001e}\u0006w4LvX5\u0010$qQ0_5\u0010-tMv\u0012e\u0010wqP9\u000b0\u0001fqP#\u0013|\bq4Y?\fd\u0006q\u0013q4N$\u001ac\u0006m%_\"\u0016\u007f\r@=_%\f\u0006?8P?\u000b.;`>Sy\u0013'\u0017f2Vy\fu\u0011u4Ly\u001ce\u0010w>Sy\u0019\u007f\u0011n0Jy<e\u0010w>S\u001b\u001ac\u0010b6[\u0010\u0010b\u000eb%l3\u0018y\u0010w#G\u0006q4S9\tu\u0003d4J\ne>L;\u001ed-b<[";
                var4_3 = "d4J\u0010\u0010b-b<[\u0007e>L;\u001ed\u0010>B#Y#\u0012u\rwqX9\r0#M>J\u0018\n|\u000f#!_$\u001e}\u0006w4LvX5\u0010$qQ0_5\u0010-tMv\u0012e\u0010wqP9\u000b0\u0001fqP#\u0013|\bq4Y?\fd\u0006q\u0013q4N$\u001ac\u0006m%_\"\u0016\u007f\r@=_%\f\u0006?8P?\u000b.;`>Sy\u0013'\u0017f2Vy\fu\u0011u4Ly\u001ce\u0010w>Sy\u0019\u007f\u0011n0Jy<e\u0010w>S\u001b\u001ac\u0010b6[\u0010\u0010b\u000eb%l3\u0018y\u0010w#G\u0006q4S9\tu\u0003d4J\ne>L;\u001ed-b<[".length();
                var1_4 = 10;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = CustomMessageFormatRegistry.a(v0, CustomMessageFormatRegistry.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u0007\\.Y|\u0006\u0013\u0012G=Gu?`\u000fR;Qo4`\u0002G3Fd";
                    var4_3 = "\u0007\\.Y|\u0006\u0013\u0012G=Gu?`\u000fR;Qo4`\u0002G3Fd".length();
                    var1_4 = 6;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 39;
                        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++] = CustomMessageFormatRegistry.a(v0, CustomMessageFormatRegistry.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;
            }
        }
        CustomMessageFormatRegistry.c = var5;
    }

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

