package j3;

import V4.C;
import com.debridstream.tv.updater.UpdateViewModel;
import com.google.firebase.sessions.settings.RemoteSettings;
import m3.AbstractC2467b;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.json.JSONObject;
import w4.C3137A;

/* JADX INFO: renamed from: j3.l, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C2360l extends C4.j implements J4.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ UpdateViewModel f19587a;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C2360l(UpdateViewModel updateViewModel, A4.d dVar) {
        super(2, dVar);
        this.f19587a = updateViewModel;
    }

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

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

    @Override // C4.a
    public final Object invokeSuspend(Object obj) {
        Object objD;
        B4.a aVar = B4.a.f492a;
        AbstractC2467b.l(obj);
        C2353e c2353e = this.f19587a.gitHubReleaseClient;
        c2353e.getClass();
        try {
            String str = "codebutter-bit";
            if (S4.p.Q0("codebutter-bit")) {
                str = null;
            }
            if (str == null) {
                throw new IllegalStateException("GITHUB_OWNER is not configured");
            }
            String str2 = S4.p.Q0("scraper") ? null : "scraper";
            if (str2 == null) {
                throw new IllegalStateException("GITHUB_REPO is not configured");
            }
            String str3 = "https://api.github.com/repos/" + str + RemoteSettings.FORWARD_SLASH_STRING + str2 + "/releases/latest";
            Request.Builder builder = new Request.Builder();
            builder.i(str3);
            builder.e("Accept", "application/vnd.github+json");
            builder.e("User-Agent", "DebridStream-Updater");
            Response responseD = c2353e.f19561a.a(builder.b()).d();
            try {
                if (!responseD.c()) {
                    throw new IllegalStateException(("GitHub API error: " + responseD.f22143d).toString());
                }
                ResponseBody responseBody = responseD.f22146j;
                if (responseBody == null) {
                    throw new IllegalStateException("Empty GitHub release response");
                }
                objD = C2353e.a(new JSONObject(responseBody.d()));
                responseD.close();
            } finally {
            }
        } catch (Throwable th) {
            objD = AbstractC2467b.d(th);
        }
        return new w4.n(objD);
    }
}
