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

import X.0Gp;
import X.9DY;
import X.9HM;
import X.AnonymousClass2HN;
import X.AnonymousClass2XC;
import X.C28963Xk;
import X.C57724eC;
import X.C57734eD;
import X.C57744eE;
import X.JMA;
import X.M12;
import X.PUt;
import X.TSt;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.ugc.aweme.network.IRetrofitFactory;
import com.bytedance.ies.ugc.aweme.network.RetrofitFactory;
import com.google.gson.Gson;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.AwemeRawAd;
import com.ss.android.ugc.aweme.utils.GsonHolder;
import com.ss.android.ugc.aweme.utils.GsonProvider;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public final class AwemeAdRankApi {
    public static final AwemeAdRankApi LIZ = new AwemeAdRankApi();
    public static final RealApi LIZIZ;
    public static final Gson LIZJ;

    public interface RealApi {
        static {
            Covode.recordClassIndex(58304);
        }

        @JMA(LIZ = "/aweme/v1/ad/rank/")
        0Gp<C57734eD> requestAwemeAdRank(@PUt(LIZ = "cached_aweme_list") String str, @PUt(LIZ = "last_ad_show_interval") long j, @PUt(LIZ = "action_mask") int i);
    }

    static {
        RealApi realApi;
        AnonymousClass2XC LIZ2;
        Covode.recordClassIndex(58303);
        IRetrofitFactory LIZ3 = RetrofitFactory.LIZ();
        Gson gson = null;
        if (LIZ3 == null || (LIZ2 = LIZ3.LIZ(9DY.LJ)) == null) {
            realApi = null;
        } else {
            realApi = (RealApi) LIZ2.LIZ(RealApi.class);
        }
        LIZIZ = realApi;
        GsonProvider LIZJ2 = GsonHolder.LIZJ();
        if (LIZJ2 != null) {
            gson = LIZJ2.LIZIZ();
        }
        LIZJ = gson;
    }

    public final void LIZ(List<? extends Aweme> list, long j, C57744eE r15) {
        String str;
        0Gp<C57734eD> requestAwemeAdRank;
        String LIZIZ2;
        Long creativeId;
        M12.LIZ(list);
        ArrayList arrayList = new ArrayList(9HM.LIZ(list, 10));
        Iterator<T> it = list.iterator();
        while (true) {
            str = "";
            if (!it.hasNext()) {
                break;
            }
            Aweme aweme = (Aweme) it.next();
            String aid = aweme.getAid();
            boolean isAd = aweme.isAd();
            if (aweme.isAd()) {
                AwemeRawAd awemeRawAd = aweme.getAwemeRawAd();
                if (awemeRawAd == null || (creativeId = awemeRawAd.getCreativeId()) == null) {
                    str = null;
                } else {
                    str = String.valueOf(creativeId.longValue());
                }
            }
            arrayList.add(new C28963Xk(aid, isAd ? 1 : 0, str, (Aweme) null, 8, (AnonymousClass2HN) null));
        }
        Gson gson = LIZJ;
        if (!(gson == null || (LIZIZ2 = gson.LIZIZ(arrayList)) == null)) {
            str = LIZIZ2;
        }
        try {
            RealApi realApi = LIZIZ;
            if (realApi != null && (requestAwemeAdRank = realApi.requestAwemeAdRank(str, j, -1)) != null) {
                requestAwemeAdRank.LIZ(new C57724eC(r15));
            }
        } catch (Exception e) {
            TSt.LIZ(e);
        }
    }
}
