package com.ss.android.ugc.aweme.commercialize.profile.talent;

import X.2ma;
import X.C3867EUt;
import X.C4389EgD;
import X.C4390EgE;
import X.C4391EgF;
import X.C4392EgG;
import X.C4393EgH;
import X.EV6;
import X.EV8;
import X.FMT;
import X.K0c;
import X.KGj;
import X.KGr;
import X.Lea;
import X.Lnj;
import X.M12;
import X.PYx;
import X.TSt;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.ies.abmock.SettingsManager;
import com.bytedance.ies.ugc.aweme.network.RetrofitFactory;
import com.ss.android.ugc.aweme.feed.model.AwemeRawAd;
import java.util.ArrayList;
import java.util.List;
import kotlin.h.b.n;
import org.json.JSONException;
import org.json.JSONObject;

public final class TalentAdRevenueShareServiceImpl implements ITalentAdRevenueShareService {
    public static final C4391EgF LJFF = new C4391EgF((byte) 0);
    public final ArrayList<String> LIZ = new ArrayList<>();
    public int LIZIZ;
    public int LIZJ = -1;
    public int LIZLLL = -1;
    public boolean LJ;
    public boolean LJI;
    public boolean LJII;
    public String LJIIIIZZ;
    public C4393EgH LJIIIZ;

    static {
        Covode.recordClassIndex(59541);
    }

    public final List<String> LIZIZ() {
        return this.LIZ;
    }

    public final boolean LIZJ() {
        return this.LJI;
    }

    public final boolean LIZ(int i) {
        int i2 = this.LIZIZ;
        if (i2 <= 0) {
            return false;
        }
        int i3 = this.LIZJ;
        if (i3 < 0) {
            return true;
        }
        if (i <= i3) {
            return false;
        }
        if (i - i3 >= i2 + ((i3 != this.LIZLLL || this.LJII) ? 0 : 1)) {
            return true;
        }
        return false;
    }

    public final int LIZ() {
        int LIZ2 = SettingsManager.LIZ().LIZ("creator_monetization_ad_upload_item_threshold", 5);
        if (LIZ2 < 0) {
            return 0;
        }
        return LIZ2;
    }

    public final void LIZLLL() {
        this.LIZ.clear();
        this.LIZJ = -1;
        this.LIZLLL = -1;
        this.LJ = false;
        this.LJI = false;
        this.LJIIIIZZ = null;
        C4392EgG.LIZ.LIZIZ(this.LJIIIZ);
    }

    public static ITalentAdRevenueShareService LJ() {
        MethodCollector.i(14580);
        ITalentAdRevenueShareService iTalentAdRevenueShareService = (ITalentAdRevenueShareService) Lnj.LIZ(ITalentAdRevenueShareService.class, false);
        if (iTalentAdRevenueShareService != null) {
            MethodCollector.o(14580);
            return iTalentAdRevenueShareService;
        }
        Object LIZIZ2 = Lnj.LIZIZ(ITalentAdRevenueShareService.class, false);
        if (LIZIZ2 != null) {
            ITalentAdRevenueShareService iTalentAdRevenueShareService2 = (ITalentAdRevenueShareService) LIZIZ2;
            MethodCollector.o(14580);
            return iTalentAdRevenueShareService2;
        }
        if (Lnj.LJLLLLLL == null) {
            synchronized (ITalentAdRevenueShareService.class) {
                try {
                    if (Lnj.LJLLLLLL == null) {
                        Lnj.LJLLLLLL = new TalentAdRevenueShareServiceImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(14580);
                    throw th;
                }
            }
        }
        TalentAdRevenueShareServiceImpl talentAdRevenueShareServiceImpl = (TalentAdRevenueShareServiceImpl) Lnj.LJLLLLLL;
        MethodCollector.o(14580);
        return talentAdRevenueShareServiceImpl;
    }

    public final void LIZ(String str) {
        if (str != null && n.LIZ(Lea.LJIIIZ(this.LIZ), str)) {
            this.LIZ.remove(str);
            this.LJII = true;
        }
    }

    public final void LIZ(AwemeRawAd awemeRawAd) {
        M12.LIZ(awemeRawAd);
        if (this.LJI) {
            JSONObject jSONObject = new JSONObject();
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put("filter_words", "not interested");
            jSONObject2.put("unified_dislike", 1);
            jSONObject.put("ad_extra_data", jSONObject2);
            KGr kGr = new KGr();
            kGr.LIZ = awemeRawAd;
            kGr.LIZLLL = jSONObject;
            FMT.LIZ("draw_ad", "dislike", kGr.LIZ(), awemeRawAd);
            KGj LIZ2 = K0c.LIZ("draw_ad", "dislike", awemeRawAd);
            LIZ2.LIZ("filter_words", "not interested");
            LIZ2.LIZ("unified_dislike", 1);
            LIZ2.LIZJ();
        }
    }

    public final void LIZ(String str, AwemeRawAd awemeRawAd) {
        M12.LIZ(str, awemeRawAd);
        KGr kGr = new KGr();
        kGr.LIZ = awemeRawAd;
        kGr.LIZIZ = str;
        FMT.LIZ("draw_ad", "otherclick", kGr.LIZ(), awemeRawAd);
        KGj LIZ2 = K0c.LIZ("draw_ad", "otherclick", awemeRawAd);
        LIZ2.LIZIZ("refer", str);
        LIZ2.LIZJ();
    }

    public final void LIZ(String str, JSONObject jSONObject) {
        JSONObject jSONObject2;
        if (str != null && jSONObject != null) {
            try {
                if (TextUtils.isEmpty(this.LJIIIIZZ)) {
                    return;
                }
                if (this.LIZ.contains(str)) {
                    String optString = jSONObject.optString("ad_extra_data");
                    if (TextUtils.isEmpty(optString)) {
                        jSONObject2 = new JSONObject();
                    } else {
                        jSONObject2 = new JSONObject(optString);
                    }
                    jSONObject2.put("creator_uid", this.LJIIIIZZ);
                    jSONObject.put("ad_extra_data", jSONObject2.toString());
                }
            } catch (JSONException e) {
                TSt.LIZ(e);
            }
        }
    }

    public final void LIZ(JSONObject jSONObject, AwemeRawAd awemeRawAd) {
        String str;
        String str2;
        String str3;
        M12.LIZ(jSONObject, awemeRawAd);
        if (awemeRawAd.getCreativeIdStr() != null && n.LIZ(awemeRawAd.getCreativeIdStr(), Lea.LJIIIZ(this.LIZ))) {
            int i = 0;
            if (jSONObject.opt("reason_id") != null) {
                i = jSONObject.optInt("reason_id");
            }
            String str4 = "";
            if (jSONObject.opt("report_from") != null) {
                str = jSONObject.optString("report_from");
                n.LIZIZ(str, str4);
            } else {
                str = str4;
            }
            if (jSONObject.opt("screenshot_uri") != null) {
                str2 = jSONObject.optString("screenshot_uri");
                n.LIZIZ(str2, str4);
            } else {
                str2 = str4;
            }
            if (jSONObject.opt("description") != null) {
                str3 = jSONObject.optString("description");
                n.LIZIZ(str3, str4);
            } else {
                str3 = str4;
            }
            int hashCode = str.hashCode();
            if (hashCode != -1755408457) {
                if (hashCode != -326696768) {
                    if (hashCode == 1820422063 && str.equals("creative")) {
                        str4 = "share_ad";
                    }
                } else if (str.equals("long_press")) {
                    str4 = "draw_ad";
                }
            } else if (str.equals("landing_page")) {
                str4 = "landing_ad";
            }
            JSONObject jSONObject2 = new JSONObject();
            JSONObject jSONObject3 = new JSONObject();
            jSONObject3.put("reason_id", i);
            jSONObject3.put("screenshot_url", str2);
            jSONObject3.put("description", str3);
            jSONObject2.put("ad_extra_data", jSONObject3);
            KGr kGr = new KGr();
            kGr.LIZ = awemeRawAd;
            kGr.LIZLLL = jSONObject2;
            FMT.LIZ(str4, "report", kGr.LIZ(), awemeRawAd);
            KGj LIZ2 = K0c.LIZ(str4, "report", awemeRawAd);
            LIZ2.LIZ("reason_id", Integer.valueOf(i));
            LIZ2.LIZ("screenshot_url", str2);
            LIZ2.LIZ("description", str3);
            LIZ2.LIZJ();
        }
    }

    public final void LIZ(boolean z, String str) {
        this.LJI = z;
        this.LJIIIIZZ = str;
        this.LJIIIZ = new C4390EgE(this);
        C4392EgG.LIZ.LIZ(this.LJIIIZ);
    }

    public final void LIZ(String str, List<String> list, int i, EV8 ev8, C3867EUt eUt) {
        int i2;
        String str2 = str;
        C3867EUt eUt2 = eUt;
        EV8 ev82 = ev8;
        List<String> list2 = list;
        M12.LIZ(str2, list2, ev82, eUt2);
        if (!this.LJ) {
            String str3 = "[";
            for (String next : list2) {
                if (true ^ n.LIZ(str3, "[")) {
                    str3 = str3 + ",";
                }
                if (!TextUtils.isEmpty(next)) {
                    str3 = str3 + next;
                }
            }
            String str4 = str3 + "]";
            Integer num = null;
            int i3 = i;
            if (ev82 == EV8.PROFILE_AD_REQUEST_SOURCE_LOAD_MORE && (i2 = this.LIZLLL) >= 0) {
                num = Integer.valueOf(i3 - i2);
            }
            this.LJ = true;
            this.LJII = false;
            Object LIZ2 = RetrofitFactory.LIZ().LIZIZ(C4389EgD.LIZ).LIZJ().LIZ(ProfileAdTalentShareApi.class);
            n.LIZIZ(LIZ2, "");
            PYx.LIZ(((ProfileAdTalentShareApi) LIZ2).getTalentProfileAd(str2, str4, i3, ev82.getSOURCE(), num), new EV6(this, i3, eUt2), 2ma.LIZ);
        }
    }
}
