package com.bytedance.sdk.component.wsy.ro;

import android.net.Uri;
import android.text.TextUtils;
import com.bytedance.sdk.component.ro.fm.ajl;
import com.bytedance.sdk.component.ro.fm.duv;
import com.bytedance.sdk.component.ro.fm.fhx;
import com.bytedance.sdk.component.ro.fm.fm;
import com.bytedance.sdk.component.ro.fm.ku;
import com.bytedance.sdk.component.ro.fm.onz;
import com.bytedance.sdk.component.ro.fm.wsy;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/* JADX INFO: loaded from: classes.dex */
public class ro extends lb {
    public static final com.bytedance.sdk.component.ro.fm.fm fm = new fm.C0038fm().fm().ro();
    public static final com.bytedance.sdk.component.ro.fm.fm ro = new fm.C0038fm().ro();
    private Map<String, String> dsz;
    private boolean duv;
    private com.bytedance.sdk.component.ro.fm.fm ku;

    public ro(ku kuVar) {
        super(kuVar);
        this.ku = fm;
        this.duv = false;
        this.dsz = new HashMap();
    }

    public void fm(boolean z10) {
        this.duv = z10;
    }

    @Override // com.bytedance.sdk.component.wsy.ro.lb
    public void fm(final com.bytedance.sdk.component.wsy.fm.fm fmVar) {
        try {
            duv.fm fmVar2 = new duv.fm();
            if (this.duv) {
                fmVar2.ro(this.wu);
            } else {
                wsy.fm fmVar3 = new wsy.fm();
                Uri uri = Uri.parse(this.wu);
                fmVar3.fm(uri.getScheme());
                fmVar3.ro(uri.getHost());
                String encodedPath = uri.getEncodedPath();
                if (!TextUtils.isEmpty(encodedPath)) {
                    if (encodedPath.startsWith("/")) {
                        encodedPath = encodedPath.substring(1);
                    }
                    fmVar3.lb(encodedPath);
                }
                Set<String> queryParameterNames = uri.getQueryParameterNames();
                if (queryParameterNames != null && queryParameterNames.size() > 0) {
                    for (String str : queryParameterNames) {
                        this.dsz.put(str, uri.getQueryParameter(str));
                    }
                }
                for (Map.Entry<String, String> entry : this.dsz.entrySet()) {
                    String key = entry.getKey();
                    String value = entry.getValue();
                    if (!TextUtils.isEmpty(key)) {
                        String strEncode = URLEncoder.encode(key, "UTF-8");
                        if (value == null) {
                            value = "";
                        }
                        fmVar3.fm(strEncode, URLEncoder.encode(value, "UTF-8"));
                    }
                }
                fmVar2.fm(fmVar3.ro());
            }
            ro(fmVar2);
            fm(fmVar2);
            fmVar2.fm(this.ku);
            fmVar2.fm((Object) yz());
            if (!TextUtils.isEmpty(this.jnr)) {
                fmVar2.fm(this.jnr);
            }
            int i10 = this.ajl;
            if (i10 > 0) {
                fmVar2.fm(i10);
            }
            this.f6701lb.fm(fmVar2.fm().ro()).fm(new com.bytedance.sdk.component.ro.fm.lb() { // from class: com.bytedance.sdk.component.wsy.ro.ro.1
                @Override // com.bytedance.sdk.component.ro.fm.lb
                public void fm(com.bytedance.sdk.component.ro.fm.ro roVar, IOException iOException) {
                    com.bytedance.sdk.component.wsy.fm.fm fmVar4 = fmVar;
                    if (fmVar4 != null) {
                        fmVar4.fm(ro.this, iOException);
                    }
                }

                @Override // com.bytedance.sdk.component.ro.fm.lb
                public void fm(com.bytedance.sdk.component.ro.fm.ro roVar, onz onzVar) throws IOException {
                    if (fmVar != null) {
                        HashMap map = new HashMap();
                        if (onzVar != null) {
                            ro.this.fm(onzVar.ef());
                            ajl ajlVarWsy = onzVar.wsy();
                            if (ajlVarWsy != null) {
                                for (int i11 = 0; i11 < ajlVarWsy.fm(); i11++) {
                                    map.put(ajlVarWsy.fm(i11), ajlVarWsy.ro(i11));
                                }
                            }
                            fhx fhxVarAjl = onzVar.ajl();
                            fmVar.fm(ro.this, new com.bytedance.sdk.component.wsy.ro(onzVar.yz(), onzVar.lb(), onzVar.jnr(), map, fhxVarAjl == null ? "" : fhxVarAjl.ro(), onzVar.ro(), onzVar.fm()));
                        }
                    }
                }
            });
        } catch (Throwable th) {
            if (fmVar != null) {
                fmVar.fm(this, new IOException(th.getMessage()));
            }
        }
    }

    @Override // com.bytedance.sdk.component.wsy.ro.lb
    public com.bytedance.sdk.component.wsy.ro fm() {
        try {
            duv.fm fmVar = new duv.fm();
            if (this.duv) {
                fmVar.ro(this.wu);
            } else {
                wsy.fm fmVar2 = new wsy.fm();
                Uri uri = Uri.parse(this.wu);
                fmVar2.fm(uri.getScheme());
                fmVar2.ro(uri.getHost());
                String encodedPath = uri.getEncodedPath();
                if (!TextUtils.isEmpty(encodedPath)) {
                    if (encodedPath.startsWith("/")) {
                        encodedPath = encodedPath.substring(1);
                    }
                    fmVar2.lb(encodedPath);
                }
                Set<String> queryParameterNames = uri.getQueryParameterNames();
                if (queryParameterNames != null && queryParameterNames.size() > 0) {
                    for (String str : queryParameterNames) {
                        this.dsz.put(str, uri.getQueryParameter(str));
                    }
                }
                for (Map.Entry<String, String> entry : this.dsz.entrySet()) {
                    String key = entry.getKey();
                    String value = entry.getValue();
                    if (!TextUtils.isEmpty(key)) {
                        String strEncode = URLEncoder.encode(key, "UTF-8");
                        if (value == null) {
                            value = "";
                        }
                        fmVar2.fm(strEncode, URLEncoder.encode(value, "UTF-8"));
                    }
                }
                fmVar.fm(fmVar2.ro());
            }
            ro(fmVar);
            fm(fmVar);
            fmVar.fm(this.ku);
            fmVar.fm((Object) yz());
            onz onzVarRo = this.f6701lb.fm(fmVar.fm().ro()).ro();
            if (onzVarRo == null) {
                return null;
            }
            fm(onzVarRo.ef());
            HashMap map = new HashMap();
            ajl ajlVarWsy = onzVarRo.wsy();
            if (ajlVarWsy != null) {
                for (int i10 = 0; i10 < ajlVarWsy.fm(); i10++) {
                    map.put(ajlVarWsy.fm(i10), ajlVarWsy.ro(i10));
                }
            }
            fhx fhxVarAjl = onzVarRo.ajl();
            return new com.bytedance.sdk.component.wsy.ro(onzVarRo.yz(), onzVarRo.lb(), onzVarRo.jnr(), map, fhxVarAjl != null ? fhxVarAjl.ro() : "", onzVarRo.ro(), onzVarRo.fm());
        } catch (Throwable unused) {
            return null;
        }
    }
}
