package com.ss.android.ugc.aweme.net.interceptor;

import X.C23868bx;
import X.C51029ef;
import X.C51409fH;
import X.C51489fP;
import X.C52349gn;
import X.C52689hL;
import X.LeS;
import X.Lea;
import X.M12;
import com.bytedance.covode.number.Covode;
import com.bytedance.retrofit2.client.Request;
import java.util.ArrayList;
import kotlin.h.b.n;
import kotlin.o.y;
import okhttp3.HttpUrl;

public final class ApiAlisgInterceptorTTNet implements C23868bx {
    public static final ArrayList<String> LIZ = LeS.LIZLLL(new String[]{"/service/2/app_log/", "/api/ad/v1/setting/", "/api/ad/splash/", "/aweme/v1/ttregion/test/", "/aweme/v1/feed/", "/aweme/v2/feed/", "/aweme/v2/category/list/", "/aweme/v1/find/", "/aweme/v1/challenge/history/intervene/"});
    public static final ArrayList<String> LIZIZ = LeS.LIZLLL(new String[]{"IN", "NP", "PK", "LK"});
    public static final ArrayList<String> LIZJ = LeS.LIZLLL(new String[]{"US", "GB", "DE", "IT", "FR", "TR", "ES", "JP", "KR", "BR", "IQ"});
    public static final C52689hL LIZLLL = new C52689hL((byte) 0);

    static {
        Covode.recordClassIndex(94727);
    }

    public final C51029ef<?> intercept(C51489fP r9) {
        HttpUrl.Builder newBuilder;
        HttpUrl.Builder newBuilder2;
        HttpUrl.Builder newBuilder3;
        M12.LIZ(r9);
        Request LIZ2 = r9.LIZ();
        if (Lea.LIZ(LIZIZ, C52349gn.LJ.LIZ().LJIIJJI.LIZ())) {
            n.LIZIZ(LIZ2, "");
            String path = LIZ2.getPath();
            for (String LIZIZ2 : LIZ) {
                n.LIZIZ(path, "");
                if (y.LIZIZ(path, LIZIZ2, false)) {
                    n.LIZIZ(LIZ2, "");
                    HttpUrl parse = HttpUrl.parse(LIZ2.getUrl());
                    if (!(parse == null || (newBuilder3 = parse.newBuilder()) == null)) {
                        String host = parse.host();
                        if (!y.LIZIZ(path, "/service/2/app_log/", false)) {
                            newBuilder3.host("api-h2.tiktokv.com");
                        } else if ("log-va.tiktokv.com".equals(host)) {
                            newBuilder3.host("log.tiktokv.com");
                        } else if ("rtlog-va.tiktokv.com".equals(host)) {
                            newBuilder3.host("rtlog.tiktokv.com");
                        }
                        C51409fH newBuilder4 = LIZ2.newBuilder();
                        newBuilder4.LIZ(newBuilder3.build().toString());
                        LIZ2 = newBuilder4.LIZ();
                    }
                }
            }
        } else if (Lea.LIZ(LIZJ, C52349gn.LJ.LIZ().LJIIJJI.LIZ())) {
            n.LIZIZ(LIZ2, "");
            HttpUrl parse2 = HttpUrl.parse(LIZ2.getUrl());
            if (!(parse2 == null || (newBuilder2 = parse2.newBuilder()) == null || !n.LIZ((Object) parse2.host(), (Object) "api-va.tiktokv.com"))) {
                newBuilder2.host("api19-va.tiktokv.com");
                C51409fH newBuilder5 = LIZ2.newBuilder();
                newBuilder5.LIZ(newBuilder2.build().toString());
                LIZ2 = newBuilder5.LIZ();
            }
        } else {
            n.LIZIZ(LIZ2, "");
            HttpUrl parse3 = HttpUrl.parse(LIZ2.getUrl());
            if (!(parse3 == null || (newBuilder = parse3.newBuilder()) == null || !n.LIZ((Object) parse3.host(), (Object) "api-va.tiktokv.com"))) {
                newBuilder.host("api16-va.tiktokv.com");
                C51409fH newBuilder6 = LIZ2.newBuilder();
                newBuilder6.LIZ(newBuilder.build().toString());
                LIZ2 = newBuilder6.LIZ();
            }
        }
        C51029ef<?> LIZ3 = r9.LIZ(LIZ2);
        n.LIZIZ(LIZ3, "");
        return LIZ3;
    }
}
