package com.ss.android.ugc.aweme.ml.impl;

import X.8cV;
import X.C0677RQb;
import X.Lnj;
import X.M12;
import X.RQD;
import X.RQZ;
import X.RRA;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.ml.api.ISmartPreloadProfileV2Service;
import com.ss.android.ugc.aweme.ml.api.SmartPreloadProfileV2Service;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public final class SmartPreloadProfileV2ServiceImpl extends SmartPreloadProfileV2Service {
    public static final RQZ LIZ = new RQZ((byte) 0);
    public boolean LIZIZ;
    public boolean LIZJ;
    public boolean LIZLLL;

    static {
        Covode.recordClassIndex(92993);
    }

    public final boolean ensureEvaluatorAvailable() {
        boolean z = true;
        if (this.LIZLLL) {
            return true;
        }
        RRA rra = C0677RQb.LIZ;
        if (rra.LIZ == null || !rra.LIZ.LIZIZ()) {
            z = false;
        }
        this.LIZLLL = z;
        return z;
    }

    public static ISmartPreloadProfileV2Service LIZ() {
        MethodCollector.i(18275);
        ISmartPreloadProfileV2Service iSmartPreloadProfileV2Service = (ISmartPreloadProfileV2Service) Lnj.LIZ(ISmartPreloadProfileV2Service.class, false);
        if (iSmartPreloadProfileV2Service != null) {
            MethodCollector.o(18275);
            return iSmartPreloadProfileV2Service;
        }
        Object LIZIZ2 = Lnj.LIZIZ(ISmartPreloadProfileV2Service.class, false);
        if (LIZIZ2 != null) {
            ISmartPreloadProfileV2Service iSmartPreloadProfileV2Service2 = (ISmartPreloadProfileV2Service) LIZIZ2;
            MethodCollector.o(18275);
            return iSmartPreloadProfileV2Service2;
        }
        if (Lnj.s == null) {
            synchronized (ISmartPreloadProfileV2Service.class) {
                try {
                    if (Lnj.s == null) {
                        Lnj.s = new SmartPreloadProfileV2ServiceImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(18275);
                    throw th;
                }
            }
        }
        SmartPreloadProfileV2Service smartPreloadProfileV2Service = (SmartPreloadProfileV2Service) Lnj.s;
        MethodCollector.o(18275);
        return smartPreloadProfileV2Service;
    }

    public final float smartJudge(Aweme aweme, Map<String, Object> map, Map<String, Object> map2) {
        float f;
        Map<String, Object> map3 = map;
        Map<String, Object> map4 = map2;
        M12.LIZ(map3, map4);
        float f2 = -1.0f;
        if (!(aweme == null || C0677RQb.LIZ.LIZIZ == null)) {
            this.LIZIZ = true;
            this.LIZJ = false;
            try {
                if (SmartPreloadProfileV2Service.debug) {
                    System.currentTimeMillis();
                }
                if (SmartPreloadProfileV2Service.debug) {
                    System.currentTimeMillis();
                }
                RRA rra = C0677RQb.LIZ;
                if (rra.LIZ != null) {
                    RQD rqd = rra.LIZ;
                    if (!rqd.LIZJ() || map3 == null || map3.isEmpty() || !rqd.LIZIZ()) {
                        SmartPreloadProfileV2Service.getDebug();
                    } else {
                        if (SmartPreloadProfileV2Service.getDebug()) {
                            Iterator<String> it = map3.keySet().iterator();
                            while (it.hasNext()) {
                                it.next();
                            }
                        }
                        HashMap hashMap = new HashMap();
                        List<String> LIZ2 = rqd.LIZIZ.LIZ(map3, rqd.LIZ(), rqd.LIZLLL.output, rqd.LIZLLL.feature_list, hashMap);
                        if (SmartPreloadProfileV2Service.getDebug()) {
                            Iterator it2 = hashMap.keySet().iterator();
                            while (it2.hasNext()) {
                                it2.next();
                            }
                        }
                        if (map4 != null && LIZ2.size() > 0) {
                            String str = LIZ2.get(0);
                            boolean equals = TextUtils.equals(str, "leave");
                            Float f3 = (Float) hashMap.get(str);
                            map4.put("label", LIZ2.get(0));
                            if (f3 == null) {
                                f = -1.0f;
                            } else if (equals) {
                                f = 1.0f - f3.floatValue();
                            } else {
                                f = f3.floatValue();
                            }
                            map4.put("probability", Float.valueOf(f));
                        }
                    }
                }
            } catch (Exception e) {
                8cV.LIZ(e);
            } catch (Throwable unused) {
            }
            if (SmartPreloadProfileV2Service.debug) {
                System.currentTimeMillis();
            }
            if (map4.containsKey("label")) {
                if (SmartPreloadProfileV2Service.debug) {
                    System.currentTimeMillis();
                }
                if (map4.get("label") != null) {
                    Object obj = map4.get("probability");
                    if (SmartPreloadProfileV2Service.debug) {
                        System.currentTimeMillis();
                    }
                    if (obj instanceof Float) {
                        f2 = ((Number) obj).floatValue();
                    }
                    this.LIZIZ = false;
                    return f2;
                }
                throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
            }
            this.LIZJ = true;
            if (SmartPreloadProfileV2Service.debug) {
                System.currentTimeMillis();
            }
            this.LIZIZ = false;
        }
        return -1.0f;
    }
}
