/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.identity.Identity
 *  com.l7tech.identity.IdentityProvider
 *  com.l7tech.objectmodel.EntityHeader
 *  com.l7tech.objectmodel.EntityHeaderSet
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.EntityTypeRegistry
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.IdentityHeader
 *  com.l7tech.objectmodel.ReadOnlyEntityManager
 *  com.l7tech.objectmodel.ScopedSearchableEntityManager
 */
package com.l7tech.server.migration;

import com.l7tech.identity.Identity;
import com.l7tech.identity.IdentityProvider;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.EntityHeaderSet;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.EntityTypeRegistry;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.IdentityHeader;
import com.l7tech.objectmodel.ReadOnlyEntityManager;
import com.l7tech.objectmodel.ScopedSearchableEntityManager;
import com.l7tech.server.identity.IdentityProviderFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

public class IdentityEntityManager
implements ReadOnlyEntityManager<Identity, IdentityHeader>,
ScopedSearchableEntityManager<IdentityHeader> {
    private final Class<? extends Identity> a;
    private final EntityType b;
    private final IdentityProviderFactory c;
    private static final String d = IdentityEntityManager.a(8, IdentityEntityManager.a("\u0003]\u001dFy5eK\u0007"));

    public IdentityEntityManager(Class<? extends Identity> clazz, IdentityProviderFactory identityProviderFactory) {
        this.a = clazz;
        this.b = EntityTypeRegistry.getEntityType(clazz);
        this.c = identityProviderFactory;
    }

    public Collection<IdentityHeader> findHeadersInScope(int n2, int n3, EntityHeader entityHeader, Map<String, String> map) throws FindException {
        String string;
        ArrayList<IdentityHeader> arrayList;
        block5: {
            String string2;
            arrayList = new ArrayList<IdentityHeader>();
            try {
                string2 = map != null ? map.get(d) : null;
            }
            catch (FindException findException) {
                throw IdentityEntityManager.a(findException);
            }
            string = string2;
            try {
                if (string != null && !string.isEmpty()) break block5;
            }
            catch (FindException findException) {
                throw IdentityEntityManager.a(findException);
            }
            string = "*";
        }
        for (IdentityProvider identityProvider : this.c.findAllIdentityProviders()) {
            if (!identityProvider.getConfig().getGoid().equals((Object)entityHeader.getGoid())) continue;
            EntityHeaderSet entityHeaderSet = identityProvider.search(new EntityType[]{this.b}, string);
            arrayList.addAll(new ArrayList(entityHeaderSet).subList(0, Math.min(entityHeaderSet.size(), n3 - arrayList.size())));
            break;
        }
        return arrayList;
    }

    public Identity findByPrimaryKey(Goid goid) throws FindException {
        return null;
    }

    public Collection<IdentityHeader> findAllHeaders() throws FindException {
        return Collections.emptyList();
    }

    public Collection<IdentityHeader> findAllHeaders(int n2, int n3) throws FindException {
        return Collections.emptyList();
    }

    public Collection<Identity> findAll() throws FindException {
        return null;
    }

    public Class<? extends Identity> getImpClass() {
        return this.a;
    }

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

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ '\u0001');
        }
        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 -> 55;
                    case 1 -> 49;
                    case 2 -> 112;
                    case 3 -> 40;
                    case 4 -> 16;
                    case 5 -> 72;
                    default -> 1;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

