/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.security.rbac.Role
 *  com.l7tech.gateway.common.security.rbac.RoleAssignment
 *  com.l7tech.identity.Group
 *  com.l7tech.objectmodel.EntityType
 *  jakarta.persistence.criteria.CriteriaBuilder
 *  jakarta.persistence.criteria.CriteriaQuery
 *  jakarta.persistence.criteria.Expression
 *  jakarta.persistence.criteria.Predicate
 *  jakarta.persistence.criteria.Root
 *  jakarta.persistence.criteria.Selection
 *  org.hibernate.HibernateException
 *  org.hibernate.Session
 */
package com.l7tech.server.security.rbac;

import com.l7tech.gateway.common.security.rbac.Role;
import com.l7tech.gateway.common.security.rbac.RoleAssignment;
import com.l7tech.identity.Group;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.server.security.rbac.RoleManagerImpl;
import com.l7tech.server.util.ReadOnlyHibernateCallback;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.criteria.Selection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.Session;

class m
extends ReadOnlyHibernateCallback<Collection<Role>> {
    final Group val$group;
    final RoleManagerImpl this$0;
    private static final String[] a;

    m(RoleManagerImpl roleManagerImpl, Group group) {
        this.this$0 = roleManagerImpl;
        this.val$group = group;
    }

    @Override
    public Set<Role> doInHibernateReadOnly(Session session) throws HibernateException, SQLException {
        CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
        CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(RoleAssignment.class);
        Root root = criteriaQuery.from(RoleAssignment.class);
        String[] stringArray = a;
        Predicate predicate = criteriaBuilder.equal((Expression)root.get(stringArray[1]), (Object)this.val$group.getId());
        predicate = criteriaBuilder.and((Expression)predicate, (Expression)criteriaBuilder.equal((Expression)root.get(stringArray[0]), (Object)this.val$group.getProviderId()));
        predicate = criteriaBuilder.and((Expression)predicate, (Expression)criteriaBuilder.equal((Expression)root.get(stringArray[2]), (Object)EntityType.GROUP.getName()));
        criteriaQuery.select((Selection)root).where((Expression)predicate);
        List list = session.createQuery(criteriaQuery).getResultList();
        HashSet<Role> hashSet = new HashSet<Role>(list.size());
        for (RoleAssignment roleAssignment : list) {
            Role role = roleAssignment.getRole();
            this.this$0.initializeLazilyLoaded(role);
            hashSet.add(role);
        }
        return hashSet;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "`vq\u0017=Q\u001fbMz\ny`{\u000f \\\u000eiMz\nujj\b L.it{";
        int n3 = "`vq\u0017=Q\u001fbMz\ny`{\u000f \\\u000eiMz\nujj\b L.it{".length();
        int n4 = 10;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = m.a(105, m.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                a = 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] ^ 0x13);
        }
        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 -> 121;
                    case 1 -> 109;
                    case 2 -> 119;
                    case 3 -> 8;
                    case 4 -> 61;
                    case 5 -> 92;
                    default -> 19;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

