/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.log.HybridDiagnosticContext
 *  com.l7tech.objectmodel.EntityUtil
 *  com.l7tech.policy.assertion.Assertion
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.assertion.PolicyAssertionException
 *  com.l7tech.util.CollectionUtils
 *  com.l7tech.util.Either
 *  com.l7tech.util.Eithers
 *  com.l7tech.util.Functions
 *  com.l7tech.util.Functions$Nullary
 *  com.l7tech.util.Functions$Unary
 */
package com.l7tech.server.policy;

import com.l7tech.common.log.HybridDiagnosticContext;
import com.l7tech.objectmodel.EntityUtil;
import com.l7tech.policy.assertion.Assertion;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.PolicyMetadata;
import com.l7tech.server.policy.ServerPolicy;
import com.l7tech.server.policy.ServerPolicyMetadata;
import com.l7tech.server.policy.ao;
import com.l7tech.server.util.Handle;
import com.l7tech.util.CollectionUtils;
import com.l7tech.util.Either;
import com.l7tech.util.Eithers;
import com.l7tech.util.Functions;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

public class ServerPolicyHandle
extends Handle<ServerPolicy> {
    private final PolicyMetadata c;
    private final ServerPolicyMetadata d;
    private static final String[] e;

    public AssertionStatus checkRequest(PolicyEnforcementContext policyEnforcementContext) throws PolicyAssertionException, IOException {
        ServerPolicy serverPolicy = (ServerPolicy)this.getTarget();
        try {
            if (serverPolicy == null) {
                throw new IllegalStateException(e[3]);
            }
        }
        catch (PolicyAssertionException policyAssertionException) {
            throw ServerPolicyHandle.a((Exception)((Object)policyAssertionException));
        }
        return (AssertionStatus)Eithers.extract2((Either)((Either)HybridDiagnosticContext.doInContext(this.c(), (Functions.Nullary)new ao(this, policyEnforcementContext, serverPolicy))));
    }

    public Assertion getPolicyAssertion() throws IOException {
        ServerPolicy serverPolicy = (ServerPolicy)this.getTarget();
        try {
            if (serverPolicy == null) {
                throw new IllegalStateException(e[2]);
            }
        }
        catch (IOException iOException) {
            throw ServerPolicyHandle.a(iOException);
        }
        return serverPolicy.getPolicyAssertion();
    }

    public PolicyMetadata getPolicyMetadata() {
        return this.c;
    }

    ServerPolicyHandle(ServerPolicy serverPolicy, PolicyMetadata policyMetadata, ServerPolicyMetadata serverPolicyMetadata) {
        super(serverPolicy);
        this.c = policyMetadata;
        this.d = serverPolicyMetadata;
    }

    ServerPolicyMetadata b() {
        return this.d;
    }

    private Map<String, Collection<String>> c() {
        String[] stringArray = e;
        return CollectionUtils.mapBuilder().put((Object)stringArray[1], Collections.singleton(this.c.getPolicyHeader().getStrId())).put((Object)stringArray[0], (Object)Functions.map((Iterable)((Iterable)this.d.getFolderPath().call()), (Functions.Unary)EntityUtil.id())).map();
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[4];
                var3_1 = 0;
                var2_2 = "M\u0014\u0019I_.\u001aB\u001f\t[\u0014\u0019DY%\u001aB\u001f";
                var4_3 = "M\u0014\u0019I_.\u001aB\u001f\t[\u0014\u0019DY%\u001aB\u001f".length();
                var1_4 = 9;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ServerPolicyHandle.a(v0, ServerPolicyHandle.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u0001g~\"&W\u001e=ne7:m/<f`1cM/!\"m81@/6{,6&@ ra`;0@**\u0001g~\"&W\u001e=ne7:m/<f`1cM/!\"m81@/6{,6&@ ra`;0@*";
                    var4_3 = "\u0001g~\"&W\u001e=ne7:m/<f`1cM/!\"m81@/6{,6&@ ra`;0@**\u0001g~\"&W\u001e=ne7:m/<f`1cM/!\"m81@/6{,6&@ ra`;0@*".length();
                    var1_4 = 42;
                    var0_5 = -1;
lbl22:
                    // 2 sources

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

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x56);
        }
        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 -> 74;
                    case 1 -> 26;
                    case 2 -> 20;
                    case 3 -> 76;
                    case 4 -> 91;
                    case 5 -> 61;
                    default -> 86;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

