/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.security.RevocationCheckPolicy
 *  com.l7tech.objectmodel.EntityHeader
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.ObjectModelException
 *  com.l7tech.objectmodel.SaveException
 *  com.l7tech.objectmodel.UpdateException
 *  org.hibernate.criterion.Criterion
 *  org.hibernate.criterion.DetachedCriteria
 *  org.hibernate.criterion.Restrictions
 *  org.springframework.orm.hibernate5.HibernateCallback
 */
package com.l7tech.server.identity.cert;

import com.l7tech.gateway.common.security.RevocationCheckPolicy;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.ObjectModelException;
import com.l7tech.objectmodel.SaveException;
import com.l7tech.objectmodel.UpdateException;
import com.l7tech.server.HibernateEntityManager;
import com.l7tech.server.identity.cert.RevocationCheckPolicyManager;
import com.l7tech.server.identity.cert.f;
import java.util.Collection;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate5.HibernateCallback;

public class RevocationCheckPolicyManagerImpl
extends HibernateEntityManager<RevocationCheckPolicy, EntityHeader>
implements RevocationCheckPolicyManager {
    private static final String m;
    private final DetachedCriteria n = DetachedCriteria.forClass((Class)this.getImpClass()).add((Criterion)Restrictions.eq((String)o[2], (Object)Boolean.TRUE));
    private static final String[] o;

    @Override
    public Goid save(RevocationCheckPolicy revocationCheckPolicy) throws SaveException {
        Goid goid = super.save(revocationCheckPolicy);
        try {
            this.updateDefault(goid, revocationCheckPolicy);
        }
        catch (ObjectModelException objectModelException) {
            throw new SaveException((Throwable)objectModelException);
        }
        return goid;
    }

    @Override
    public void update(RevocationCheckPolicy revocationCheckPolicy) throws UpdateException {
        super.update(revocationCheckPolicy);
        try {
            this.updateDefault(revocationCheckPolicy.getGoid(), revocationCheckPolicy);
        }
        catch (ObjectModelException objectModelException) {
            throw new UpdateException((Throwable)objectModelException);
        }
    }

    public Class getImpClass() {
        return RevocationCheckPolicy.class;
    }

    @Override
    public Class getInterfaceClass() {
        return RevocationCheckPolicy.class;
    }

    @Override
    public String getTableName() {
        return o[1];
    }

    @Override
    public void updateDefault(Goid goid, RevocationCheckPolicy revocationCheckPolicy) throws FindException, UpdateException {
        if (revocationCheckPolicy.isDefaultPolicy()) {
            Collection collection = this.findAll();
            for (RevocationCheckPolicy revocationCheckPolicy2 : collection) {
                try {
                    try {
                        if (!revocationCheckPolicy2.isDefaultPolicy() || revocationCheckPolicy2.getGoid().equals((Object)goid)) continue;
                    }
                    catch (FindException findException) {
                        throw RevocationCheckPolicyManagerImpl.a(findException);
                    }
                    revocationCheckPolicy2.setDefaultPolicy(false);
                    this.update(revocationCheckPolicy2);
                }
                catch (FindException findException) {
                    throw RevocationCheckPolicyManagerImpl.a(findException);
                }
            }
        }
    }

    @Override
    public RevocationCheckPolicy getDefaultPolicy() throws FindException {
        return (RevocationCheckPolicy)this.getHibernateTemplate().execute((HibernateCallback)new f(this));
    }

    private static FindException a(FindException findException) {
        return findException;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "U2p\u0003U2p\rC4f\u0001|Knw>l\tj^";
        int n3 = "U2p\u0003U2p\rC4f\u0001|Knw>l\tj^".length();
        int n4 = 3;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = RevocationCheckPolicyManagerImpl.b(124, RevocationCheckPolicyManagerImpl.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                o = stringArray;
                m = o[0];
                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] ^ 0x66);
        }
        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 -> 91;
                    case 1 -> 45;
                    case 2 -> 124;
                    case 3 -> 28;
                    case 4 -> 117;
                    case 5 -> 91;
                    default -> 102;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

