package i3;

import java.io.IOException;
import m3.AbstractC2467b;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.json.JSONException;
import org.json.JSONObject;
import w4.C3137A;

/* JADX INFO: renamed from: i3.b, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C2268b extends C4.j implements J4.e {
    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        return new C2268b(2, dVar);
    }

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

    @Override // C4.a
    public final Object invokeSuspend(Object obj) throws JSONException, IOException {
        B4.a aVar = B4.a.f492a;
        AbstractC2467b.l(obj);
        JSONObject jSONObjectPut = new JSONObject().put("client_id", "cb6c23120401d06808b06c16c78d0e54e1953df0fce43d921280c708619c1b34");
        Request.Builder builder = new Request.Builder();
        builder.i("https://api.trakt.tv/oauth/device/code");
        builder.a("Content-Type", "application/json");
        String str = W.d.f8386g;
        if (str == null) {
            str = "DebridStream/3.0.0";
        }
        builder.a("User-Agent", str);
        RequestBody.Companion companion = RequestBody.f22136a;
        String string = jSONObjectPut.toString();
        kotlin.jvm.internal.o.g(string, "toString(...)");
        MediaType.f22043d.getClass();
        MediaType mediaTypeB = MediaType.Companion.b("application/json");
        companion.getClass();
        builder.h(RequestBody.Companion.a(string, mediaTypeB));
        Response responseD = AbstractC2270d.f18921a.a(builder.b()).d();
        try {
            ResponseBody responseBody = responseD.f22146j;
            String strD = responseBody != null ? responseBody.d() : null;
            if (strD == null) {
                strD = "";
            }
            if (!responseD.c()) {
                throw new IOException("Trakt device code failed: HTTP " + responseD.f22143d + " " + strD);
            }
            JSONObject jSONObject = new JSONObject(strD);
            String string2 = jSONObject.getString("device_code");
            kotlin.jvm.internal.o.g(string2, "getString(...)");
            String string3 = jSONObject.getString("user_code");
            kotlin.jvm.internal.o.g(string3, "getString(...)");
            String string4 = jSONObject.getString("verification_url");
            kotlin.jvm.internal.o.g(string4, "getString(...)");
            C2267a c2267a = new C2267a(jSONObject.getInt("expires_in"), jSONObject.getInt("interval"), string2, string3, string4);
            responseD.close();
            return c2267a;
        } finally {
        }
    }
}
