package com.ss.android.ugc.aweme.feed.api;

import X.2kf;
import X.3Xo;
import X.AnonymousClass8C2;
import X.AnonymousClass8C3;
import X.AnonymousClass8CA;
import X.C23868bx;
import X.C46899Vg;
import X.C50759eE;
import X.C51029ef;
import X.C51489fP;
import X.M12;
import com.bytedance.covode.number.Covode;
import com.bytedance.retrofit2.client.Request;
import kotlin.o.z;

public final class FetchNetworkInfoInterceptor implements C23868bx {
    public volatile boolean LIZ;
    public volatile int LIZIZ;

    static {
        Covode.recordClassIndex(76791);
    }

    public final C51029ef<?> intercept(C51489fP r14) {
        Request request;
        C51029ef<?> r7;
        Object obj;
        int i;
        String str;
        String url;
        String url2;
        C50759eE r0;
        String url3;
        int i2 = 1;
        Request request2 = null;
        if (r14 != null) {
            try {
                request = r14.LIZ();
                r7 = r14.LIZ(request);
            } catch (Throwable th) {
                if (r14 != null) {
                    request2 = r14.LIZ();
                }
                if (3Xo.LIZ(request2) && request2 != null && (url3 = request2.getUrl()) != null && z.LIZ(url3, "is_cold_start=1", false)) {
                    this.LIZ = true;
                    if (z.LIZ(url3, "first_retry", false)) {
                        i2 = 2;
                    }
                    this.LIZIZ = i2;
                }
                throw th;
            }
        } else {
            request = null;
            r7 = null;
        }
        if (!3Xo.LIZ(request)) {
            return r7;
        }
        if (r7 == null || (r0 = r7.LIZ) == null) {
            obj = null;
        } else {
            obj = r0.LJFF;
        }
        if (obj instanceof C46899Vg) {
            long j = ((C46899Vg) obj).LIZJ;
            if (j <= 0) {
                return r7;
            }
            String str2 = ((C46899Vg) obj).LJJI;
            if (request == null || (url2 = request.getUrl()) == null || !z.LIZ(url2, "first_retry", false)) {
                i = 0;
            } else {
                i = 1;
            }
            if (this.LIZ && request != null && (url = request.getUrl()) != null && z.LIZ(url, "pull_type=0", false)) {
                this.LIZ = false;
                this.LIZIZ = 0;
                i += this.LIZIZ;
            }
            Integer valueOf = Integer.valueOf(i);
            if (request != null) {
                str = request.getUrl();
            } else {
                str = null;
            }
            AnonymousClass8C2 r8 = new AnonymousClass8C2(str2, valueOf, str);
            M12.LIZ(r8);
            AnonymousClass8C3.LIZ.putIfAbsent(Long.valueOf(j), r8);
            T t = r7.LIZIZ;
            if (t instanceof AnonymousClass8CA) {
                ((AnonymousClass8CA) t).setNetworkInfoKey(Long.valueOf(j));
            }
        } else {
            2kf.LIZ(4, "FetchNetworkInfoInterceptor", "isn't BaseHttpRequestInfo:".concat(String.valueOf(obj)));
        }
        return r7;
    }
}
