package com.bytedance.sdk.component.fm;

import com.bytedance.sdk.component.fm.lb;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.json.JSONException;

/* JADX INFO: loaded from: classes.dex */
class ajl {
    private final wsy fm;
    private final ku wsy;
    private final com.bytedance.sdk.component.fm.fm wu;
    private final Map<String, ro> ro = new HashMap();

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private final qhl<String, gof> f6615lb = new qhl<>();
    private final Map<String, lb.ro> yz = new HashMap();
    private final List<onz> jnr = new ArrayList();
    private final Set<lb> ajl = new HashSet();

    public static final class fm {
        boolean fm;
        String ro;

        private fm(boolean z10, String str) {
            this.fm = z10;
            this.ro = str;
        }
    }

    public ajl(ef efVar, com.bytedance.sdk.component.fm.fm fmVar) {
        this.wu = fmVar;
        this.fm = efVar.yz;
        this.wsy = efVar.wu;
    }

    public fm fm(onz onzVar, jnr jnrVar) throws Exception {
        ro roVar = this.ro.get(onzVar.yz);
        if (roVar != null) {
            try {
                if (roVar instanceof yz) {
                    onzVar.toString();
                    return fm(onzVar, (yz) roVar, jnrVar);
                }
            } catch (IllegalStateException unused) {
                onzVar.toString();
                this.jnr.add(onzVar);
                return new fm(false, gqi.fm());
            }
        }
        gof gofVarFm = this.f6615lb.fm(onzVar.yz);
        if (gofVarFm != null) {
            onzVar.toString();
            return fm(onzVar, gofVarFm, jnrVar);
        }
        lb.ro roVar2 = this.yz.get(onzVar.yz);
        if (roVar2 == null) {
            onzVar.toString();
            return null;
        }
        lb lbVarFm = roVar2.fm();
        lbVarFm.fm(onzVar.yz);
        onzVar.toString();
        return fm(onzVar, lbVarFm, jnrVar);
    }

    public void fm(String str, yz<?, ?> yzVar) {
        yzVar.fm(str);
        this.ro.put(str, yzVar);
    }

    public void fm(Set<String> set, gof<?, ?> gofVar) {
        gofVar.fm(set);
        this.f6615lb.fm(set, gofVar);
        Objects.toString(set);
    }

    public void fm(String str, lb.ro roVar) {
        this.yz.put(str, roVar);
    }

    public void fm() {
        Iterator<lb> it = this.ajl.iterator();
        while (it.hasNext()) {
            it.next().jnr();
        }
        this.ajl.clear();
        this.ro.clear();
        this.yz.clear();
        this.f6615lb.fm();
    }

    private fm fm(onz onzVar, yz yzVar, jnr jnrVar) throws Exception {
        return new fm(true, gqi.fm(this.fm.fm(yzVar.fm(onzVar.yz, fm(onzVar.jnr, (ro) yzVar), jnrVar)), yzVar.ro()));
    }

    private fm fm(final onz onzVar, final lb lbVar, jnr jnrVar) throws Exception {
        this.ajl.add(lbVar);
        lbVar.fm(fm(onzVar.jnr, lbVar), jnrVar, new lb.fm() { // from class: com.bytedance.sdk.component.fm.ajl.1
            @Override // com.bytedance.sdk.component.fm.lb.fm
            public void fm(Object obj) {
                if (ajl.this.wu == null) {
                    return;
                }
                ajl.this.wu.ro(gqi.fm(ajl.this.fm.fm(obj), lbVar.ro()), onzVar);
                ajl.this.ajl.remove(lbVar);
            }

            @Override // com.bytedance.sdk.component.fm.lb.fm
            public void fm(Throwable th) {
                if (ajl.this.wu == null) {
                    return;
                }
                ajl.this.wu.ro(gqi.fm(th), onzVar);
                ajl.this.ajl.remove(lbVar);
            }
        });
        return new fm(false, gqi.fm());
    }

    private Object fm(String str, ro roVar) throws JSONException {
        return this.fm.fm(str, fm(roVar)[0]);
    }

    private static Type[] fm(Object obj) {
        Type genericSuperclass = obj.getClass().getGenericSuperclass();
        if (genericSuperclass != null) {
            return ((ParameterizedType) genericSuperclass).getActualTypeArguments();
        }
        throw new IllegalStateException("Method is not parameterized?!");
    }
}
