package U4;

import O6.p;
import Z6.InterfaceC0382w;
import com.google.android.gms.internal.measurement.C1;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLConnection;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes.dex */
public final class f extends G6.i implements p {

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public int f6737u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final /* synthetic */ g f6738v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final /* synthetic */ LinkedHashMap f6739w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final /* synthetic */ c f6740x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final /* synthetic */ d f6741y;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public f(g gVar, LinkedHashMap linkedHashMap, c cVar, d dVar, E6.d dVar2) {
        super(2, dVar2);
        this.f6738v = gVar;
        this.f6739w = linkedHashMap;
        this.f6740x = cVar;
        this.f6741y = dVar;
    }

    @Override // O6.p
    public final Object k(Object obj, Object obj2) {
        return ((f) m((E6.d) obj2, (InterfaceC0382w) obj)).p(A6.n.f457a);
    }

    @Override // G6.a
    public final E6.d m(E6.d dVar, Object obj) {
        c cVar = this.f6740x;
        d dVar2 = this.f6741y;
        return new f(this.f6738v, this.f6739w, cVar, dVar2, dVar);
    }

    /* JADX WARN: Removed duplicated region for block: B:36:0x00d7 A[RETURN] */
    @Override // G6.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object p(Object obj) throws Throwable {
        F6.a aVar = F6.a.f2580q;
        int i = this.f6737u;
        d dVar = this.f6741y;
        A6.n nVar = A6.n.f457a;
        try {
        } catch (Exception e8) {
            String message = e8.getMessage();
            if (message == null) {
                message = e8.toString();
            }
            this.f6737u = 3;
            dVar.k(message, this);
            if (nVar == aVar) {
            }
        }
        if (i == 0) {
            C1.N(obj);
            URLConnection uRLConnectionOpenConnection = g.a(this.f6738v).openConnection();
            P6.g.c(uRLConnectionOpenConnection, "null cannot be cast to non-null type javax.net.ssl.HttpsURLConnection");
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) uRLConnectionOpenConnection;
            httpsURLConnection.setRequestMethod("GET");
            httpsURLConnection.setRequestProperty("Accept", "application/json");
            for (Map.Entry entry : this.f6739w.entrySet()) {
                httpsURLConnection.setRequestProperty((String) entry.getKey(), (String) entry.getValue());
            }
            int responseCode = httpsURLConnection.getResponseCode();
            if (responseCode == 200) {
                InputStream inputStream = httpsURLConnection.getInputStream();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                StringBuilder sb = new StringBuilder();
                while (true) {
                    String line = bufferedReader.readLine();
                    if (line == null) {
                        break;
                    }
                    sb.append(line);
                }
                bufferedReader.close();
                inputStream.close();
                JSONObject jSONObject = new JSONObject(sb.toString());
                c cVar = this.f6740x;
                this.f6737u = 1;
                if (cVar.k(jSONObject, this) == aVar) {
                    return aVar;
                }
            } else {
                this.f6737u = 2;
                dVar.k("Bad response code: " + responseCode, this);
                if (nVar == aVar) {
                    return aVar;
                }
            }
        } else {
            if (i != 1 && i != 2 && i != 3) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            C1.N(obj);
        }
        return nVar;
    }
}
