/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.EntityHeader
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.util.CollectionUtils$MapBuilder
 *  com.l7tech.util.Functions$Ternary
 *  org.jetbrains.annotations.NotNull
 */
package com.l7tech.server.bundling;

import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.server.bundling.EntityMappingInstructions;
import com.l7tech.server.bundling.y;
import com.l7tech.util.CollectionUtils;
import com.l7tech.util.Functions;
import java.util.Map;
import org.jetbrains.annotations.NotNull;

public class MappingInstructionsBuilder {
    private static final Functions.Ternary<EntityMappingInstructions, EntityHeader, EntityMappingInstructions.MappingAction, EntityMappingInstructions.TargetMapping.Type> a;
    @NotNull
    private final Map<EntityType, Functions.Ternary<EntityMappingInstructions, EntityHeader, EntityMappingInstructions.MappingAction, EntityMappingInstructions.TargetMapping.Type>> b = CollectionUtils.MapBuilder.builder().map();
    private static final String[] c;

    public EntityMappingInstructions createDefaultMapping(EntityHeader entityHeader, EntityMappingInstructions.MappingAction mappingAction, EntityMappingInstructions.TargetMapping.Type type) {
        Functions.Ternary<EntityMappingInstructions, EntityHeader, EntityMappingInstructions.MappingAction, EntityMappingInstructions.TargetMapping.Type> ternary = this.b.get(entityHeader.getType());
        try {
            if (ternary != null) {
                return (EntityMappingInstructions)ternary.call((Object)entityHeader, (Object)mappingAction, (Object)type);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw MappingInstructionsBuilder.a(illegalStateException);
        }
        return (EntityMappingInstructions)a.call((Object)entityHeader, (Object)mappingAction, (Object)type);
    }

    public void registerMappingInstructionBuilder(EntityType entityType, Functions.Ternary<EntityMappingInstructions, EntityHeader, EntityMappingInstructions.MappingAction, EntityMappingInstructions.TargetMapping.Type> ternary) {
        try {
            if (this.b.containsKey(entityType)) {
                throw new IllegalStateException(c[1] + String.valueOf(entityType) + c[0]);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw MappingInstructionsBuilder.a(illegalStateException);
        }
        this.b.put(entityType, ternary);
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[2];
        int n2 = 0;
        String string = "0u\u000eHm\b\u000fyrFBq\b\u000fqm\u0014H~\tV0s\u0003Jv\u001e[us\u0003I1.S`\bCp\u0019\u000fqe\u0002\r~MBqq\u0016Dq\n\u000fyo\u0015Ym\u0018Ldh\tClMMeh\nIz\u001f\u000fvn\u0014\r";
        int n3 = "0u\u000eHm\b\u000fyrFBq\b\u000fqm\u0014H~\tV0s\u0003Jv\u001e[us\u0003I1.S`\bCp\u0019\u000fqe\u0002\r~MBqq\u0016Dq\n\u000fyo\u0015Ym\u0018Ldh\tClMMeh\nIz\u001f\u000fvn\u0014\r".length();
        int n4 = 33;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = MappingInstructionsBuilder.a(53, MappingInstructionsBuilder.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                c = stringArray;
                a = new y();
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static IllegalStateException a(IllegalStateException illegalStateException) {
        return illegalStateException;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x1A);
        }
        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 -> 37;
                    case 1 -> 52;
                    case 2 -> 83;
                    case 3 -> 24;
                    case 4 -> 42;
                    case 5 -> 88;
                    default -> 26;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

