package com.ss.android.account.adapter;

import X.AnonymousClass8BD;
import X.AnonymousClass8OC;
import X.C148586a;
import X.C33098qq;
import X.C33108qr;
import X.C33188qz;
import X.C51029ef;
import X.C53379iS;
import android.content.Context;
import android.util.Pair;
import com.bytedance.covode.number.Covode;
import com.bytedance.retrofit2.mime.TypedFile;
import com.bytedance.retrofit2.mime.TypedOutput;
import com.bytedance.retrofit2.mime.TypedString;
import com.bytedance.ttnet.INetworkApi;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class NetworkAdapter implements C33188qz {
    static {
        Covode.recordClassIndex(47764);
    }

    public final int LIZ(Context context, Throwable th) {
        return 0;
    }

    private C33108qr LIZ(C51029ef<String> r8) {
        String str;
        int i;
        if (r8 == null) {
            return null;
        }
        if (r8.LIZ != null) {
            str = r8.LIZ.LIZ;
            i = r8.LIZ.LIZIZ;
        } else {
            str = "";
            i = -1;
        }
        ArrayList arrayList = new ArrayList();
        List<AnonymousClass8BD> list = r8.LIZ.LIZLLL;
        if (list != null && list.size() > 0) {
            for (AnonymousClass8BD next : list) {
                if (next != null) {
                    arrayList.add(new C33098qq(next.LIZ, next.LIZIZ));
                }
            }
        }
        return new C33108qr(str, i, arrayList, (String) r8.LIZIZ);
    }

    public final C33108qr LIZ(String str, List<C33098qq> list) {
        C51029ef r0 = null;
        if (!C148586a.LIZ(str)) {
            LinkedHashMap linkedHashMap = new LinkedHashMap();
            Pair<String, String> LIZ = AnonymousClass8OC.LIZ(str, (Map<String, String>) linkedHashMap);
            String str2 = (String) LIZ.second;
            INetworkApi iNetworkApi = (INetworkApi) C53379iS.LIZ((String) LIZ.first, INetworkApi.class);
            LinkedList linkedList = new LinkedList();
            if (!list.isEmpty()) {
                for (C33098qq next : list) {
                    if (next != null) {
                        linkedList.add(new AnonymousClass8BD(next.LIZ, next.LIZIZ));
                    }
                }
            }
            if (iNetworkApi != null) {
                r0 = iNetworkApi.doGet(true, Integer.MAX_VALUE, str2, linkedHashMap, linkedList, (Object) null).execute();
            }
        }
        return LIZ(r0);
    }

    public final C33108qr LIZ(String str, Map<String, String> map, List<C33098qq> list) {
        C51029ef r0 = null;
        if (!C148586a.LIZ(str)) {
            LinkedHashMap linkedHashMap = new LinkedHashMap();
            Pair<String, String> LIZ = AnonymousClass8OC.LIZ(str, (Map<String, String>) linkedHashMap);
            String str2 = (String) LIZ.second;
            INetworkApi iNetworkApi = (INetworkApi) C53379iS.LIZ((String) LIZ.first, INetworkApi.class);
            LinkedList linkedList = new LinkedList();
            if (list.size() != 0) {
                for (C33098qq next : list) {
                    if (next != null) {
                        linkedList.add(new AnonymousClass8BD(next.LIZ, next.LIZIZ));
                    }
                }
            }
            LinkedHashMap linkedHashMap2 = new LinkedHashMap();
            if (!map.isEmpty()) {
                linkedHashMap2.putAll(map);
            }
            if (iNetworkApi != null) {
                r0 = iNetworkApi.doPost(Integer.MAX_VALUE, str2, linkedHashMap, linkedHashMap2, linkedList, (Object) null).execute();
            }
        }
        return LIZ(r0);
    }

    private C51029ef<String> LIZ(int i, String str, Map<String, TypedOutput> map, List<C33098qq> list) {
        if (C148586a.LIZ(str)) {
            return null;
        }
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        Pair<String, String> LIZ = AnonymousClass8OC.LIZ(str, (Map<String, String>) linkedHashMap);
        String str2 = (String) LIZ.second;
        INetworkApi iNetworkApi = (INetworkApi) C53379iS.LIZ((String) LIZ.first, INetworkApi.class);
        LinkedList linkedList = new LinkedList();
        if (list != null && list.size() > 0) {
            for (C33098qq next : list) {
                linkedList.add(new AnonymousClass8BD(next.LIZ, next.LIZIZ));
            }
        }
        LinkedHashMap linkedHashMap2 = new LinkedHashMap();
        Map<String, TypedOutput> map2 = map;
        if (!linkedHashMap2.isEmpty()) {
            for (Map.Entry entry : linkedHashMap2.entrySet()) {
                if (entry != null) {
                    map2.put(entry.getKey(), new TypedString((String) entry.getValue()));
                }
            }
        }
        if (iNetworkApi != null) {
            return iNetworkApi.postMultiPart(Integer.MAX_VALUE, str2, linkedHashMap, map2, linkedList).execute();
        }
        return null;
    }

    public final C33108qr LIZ(String str, Map<String, String> map, String str2, String str3, List<C33098qq> list) {
        if (C148586a.LIZ(str)) {
            return null;
        }
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        if (!map.isEmpty()) {
            for (Map.Entry next : map.entrySet()) {
                linkedHashMap.put(next.getKey(), new TypedString((String) next.getValue()));
            }
        }
        linkedHashMap.put(str2, new TypedFile((String) null, new File(str3)));
        return LIZ(LIZ(Integer.MAX_VALUE, str, linkedHashMap, list));
    }
}
