package h3;

import com.debridstream.tv.screens.CloudManagerViewModel;
import java.io.IOException;
import java.util.Map;
import m3.AbstractC2467b;
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import w4.C3137A;
import x4.AbstractC3251q;

/* JADX INFO: loaded from: classes.dex */
public final class V extends C4.j implements J4.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ N2.s f17508a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ CloudManagerViewModel f17509b;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public V(N2.s sVar, CloudManagerViewModel cloudManagerViewModel, A4.d dVar) {
        super(2, dVar);
        this.f17508a = sVar;
        this.f17509b = cloudManagerViewModel;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        return new V(this.f17508a, this.f17509b, dVar);
    }

    @Override // J4.e
    public final Object invoke(Object obj, Object obj2) {
        return ((V) create((V4.C) obj, (A4.d) obj2)).invokeSuspend(C3137A.f25453a);
    }

    @Override // C4.a
    public final Object invokeSuspend(Object obj) throws IOException {
        RequestBody requestBodyA;
        B4.a aVar = B4.a.f492a;
        AbstractC2467b.l(obj);
        N2.s sVar = this.f17508a;
        Map map = sVar.f5249c;
        Map map2 = sVar.f5252f;
        if (map2 != null) {
            MultipartBody.Builder builder = new MultipartBody.Builder(0);
            builder.c(MultipartBody.f22051h);
            for (Map.Entry entry : map2.entrySet()) {
                builder.a((String) entry.getKey(), (String) entry.getValue());
            }
            requestBodyA = builder.b();
        } else {
            Map map3 = sVar.f5251e;
            if (map3 != null) {
                String strM0 = AbstractC3251q.m0(map3.entrySet(), "&", null, null, new a0.I0(28), 30);
                RequestBody.Companion companion = RequestBody.f22136a;
                MediaType.f22043d.getClass();
                MediaType mediaTypeB = MediaType.Companion.b("application/x-www-form-urlencoded");
                companion.getClass();
                requestBodyA = RequestBody.Companion.a(strM0, mediaTypeB);
            } else {
                String str = sVar.f5250d;
                if (str != null) {
                    String str2 = (String) map.get("Content-Type");
                    if (str2 == null) {
                        str2 = "application/json";
                    }
                    RequestBody.Companion companion2 = RequestBody.f22136a;
                    MediaType.f22043d.getClass();
                    MediaType mediaTypeB2 = MediaType.Companion.b(str2);
                    companion2.getClass();
                    requestBodyA = RequestBody.Companion.a(str, mediaTypeB2);
                } else {
                    requestBodyA = null;
                }
            }
        }
        Request.Builder builder2 = new Request.Builder();
        builder2.i(sVar.f5247a);
        builder2.g(sVar.f5248b, requestBodyA);
        for (Map.Entry entry2 : map.entrySet()) {
            builder2.a((String) entry2.getKey(), (String) entry2.getValue());
        }
        Response responseD = this.f17509b.okHttpClient.a(builder2.b()).d();
        Headers headers = responseD.f22145f;
        int i6 = responseD.f22143d;
        try {
            try {
                ResponseBody responseBody = responseD.f22146j;
                String strB0 = responseBody != null ? e4.C.b0(responseBody) : null;
                N2.t tVar = new N2.t(responseD.c(), i6, strB0 != null ? strB0 : "", headers.k());
                responseD.close();
                return tVar;
            } catch (IOException unused) {
                N2.t tVar2 = new N2.t(false, i6, "", headers.k());
                responseD.close();
                return tVar2;
            }
        } finally {
        }
    }
}
