/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.policy.Policy
 *  com.l7tech.policy.PolicyHeader
 *  org.jetbrains.annotations.Nullable
 */
package com.l7tech.server.policy;

import com.l7tech.objectmodel.Goid;
import com.l7tech.policy.Policy;
import com.l7tech.policy.PolicyHeader;
import com.l7tech.server.policy.PolicyMetadata;
import com.l7tech.server.policy.ServerPolicy;
import com.l7tech.server.policy.ServerPolicyHandle;
import com.l7tech.server.policy.ServerPolicyMetadata;
import java.io.Closeable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.jetbrains.annotations.Nullable;

class aa
implements Closeable {
    private final Goid a;
    private final Policy b;
    private final ServerPolicyHandle c;
    private final ServerPolicy d;
    private final Goid e;
    private final Set<Goid> f;
    private boolean g = false;
    private static final String[] h;

    private aa() {
        this.a = null;
        this.b = null;
        this.c = null;
        this.d = null;
        this.e = null;
        this.f = null;
    }

    private aa(Policy policy, ServerPolicy serverPolicy, Set<Goid> set) {
        if (policy == null) {
            String[] stringArray = h;
            throw new IllegalArgumentException(stringArray[1]);
        }
        try {
            if (serverPolicy == null) {
                throw new IllegalArgumentException(h[2]);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw aa.a(illegalArgumentException);
        }
        try {
            this.a = policy.getGoid();
            this.b = policy;
            this.c = (ServerPolicyHandle)serverPolicy.ref();
            this.d = serverPolicy;
            this.e = null;
            this.f = new HashSet<Goid>();
            if (set != null) {
                this.f.addAll(set);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw aa.a(illegalArgumentException);
        }
    }

    private aa(Policy policy, @Nullable Goid goid) {
        if (policy == null) {
            throw new IllegalArgumentException(h[0]);
        }
        this.a = policy.getGoid();
        this.b = policy;
        this.c = null;
        this.d = null;
        this.e = goid;
        this.f = new HashSet<Goid>();
    }

    private ServerPolicyMetadata a() {
        try {
            if (this.c == null) {
                return null;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw aa.a(illegalArgumentException);
        }
        return this.c.b();
    }

    private Set<Goid> b() {
        Set<Goid> set;
        block4: {
            block2: {
                block3: {
                    try {
                        if (this.c != null) break block2;
                        if (this.e != null) break block3;
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw aa.a(illegalArgumentException);
                    }
                    set = Collections.emptySet();
                    break block4;
                }
                set = Collections.singleton(this.e);
                break block4;
            }
            set = this.c.b().getUsedPolicyIds(false);
        }
        return set;
    }

    public boolean isValid() {
        boolean bl2;
        try {
            bl2 = this.c != null;
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw aa.a(illegalArgumentException);
        }
        return bl2;
    }

    boolean c() {
        return this.g;
    }

    void d() {
        this.g = true;
    }

    @Override
    public void close() {
        try {
            if (this.c != null) {
                this.c.close();
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw aa.a(illegalArgumentException);
        }
    }

    public PolicyMetadata getPolicyMetadata() {
        try {
            if (this.c == null) {
                return null;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw aa.a(illegalArgumentException);
        }
        return this.c.getPolicyMetadata();
    }

    public PolicyHeader getPolicyHeader() {
        block4: {
            try {
                try {
                    if (this.c != null && this.c.getPolicyMetadata() != null) break block4;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw aa.a(illegalArgumentException);
                }
                return null;
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw aa.a(illegalArgumentException);
            }
        }
        return this.c.getPolicyMetadata().getPolicyHeader();
    }

    private static IllegalArgumentException a(IllegalArgumentException illegalArgumentException) {
        return illegalArgumentException;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = ")&k\u0017G\u0002d4<t\n\u0004\u0015+-ie\u001b\u0004\u001515%\u0017)&k\u0017G\u0002d4<t\n\u0004\u0015+-ie\u001b\u0004\u001515%\u001d*,u\bA\t\u00146%n\u001d][),:s^J\u00140y+b^J\u000e(5";
        int n3 = ")&k\u0017G\u0002d4<t\n\u0004\u0015+-ie\u001b\u0004\u001515%\u0017)&k\u0017G\u0002d4<t\n\u0004\u0015+-ie\u001b\u0004\u001515%\u001d*,u\bA\t\u00146%n\u001d][),:s^J\u00140y+b^J\u000e(5".length();
        int n4 = 23;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = aa.a(28, aa.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                h = stringArray;
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x58);
        }
        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 -> 69;
                    case 1 -> 85;
                    case 2 -> 27;
                    case 3 -> 98;
                    case 4 -> 56;
                    case 5 -> 103;
                    default -> 88;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

