package com.ss.android.ugc.aweme.compliance.common.serviceimpl;

import X.2HN;
import X.36a;
import X.49y;
import X.4A7;
import X.C04537he;
import X.C50119dC;
import X.Crj;
import X.Lnj;
import X.M12;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.helios.api.config.AbstractSettingsModel;
import com.google.gson.Gson;
import com.google.gson.m;
import com.ss.android.ugc.aweme.compliance.api.model.InterfaceControlRule;
import com.ss.android.ugc.aweme.compliance.api.model.InterfaceControlSettings;
import com.ss.android.ugc.aweme.compliance.api.model.RuleConfig;
import com.ss.android.ugc.aweme.compliance.api.services.monitor.IComplianceMonitorAdapter;
import com.ss.android.ugc.aweme.compliance.api.services.monitor.IComplianceMonitorService;
import com.ss.android.ugc.aweme.compliance.common.enums.ConfigTypeEnum;
import com.ss.android.ugc.aweme.ruler_adapter_api.RuleEngineSettingsModel;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import kotlin.h.b.n;
import kotlin.o.z;

public final class ComplianceMonitorServiceImpl implements IComplianceMonitorService {
    public final Object LIZ = new Object();
    public volatile InterfaceControlSettings LIZIZ;
    public final List<4A7> LIZJ = new ArrayList();
    public final Crj LIZLLL = C04537he.LIZ(new C50119dC(this));

    static {
        Covode.recordClassIndex(61368);
    }

    private final IComplianceMonitorAdapter LJII() {
        return (IComplianceMonitorAdapter) this.LIZLLL.getValue();
    }

    public final void LIZIZ() {
        this.LIZIZ = null;
    }

    public final AbstractSettingsModel LIZJ() {
        return LJII().LIZJ();
    }

    public final RuleEngineSettingsModel LIZLLL() {
        return LJII().LIZLLL();
    }

    public final m LJ() {
        return LJII().LJ();
    }

    public final m LJFF() {
        return LJII().LJFF();
    }

    public static IComplianceMonitorService LJI() {
        MethodCollector.i(480);
        IComplianceMonitorService iComplianceMonitorService = (IComplianceMonitorService) Lnj.LIZ(IComplianceMonitorService.class, false);
        if (iComplianceMonitorService != null) {
            MethodCollector.o(480);
            return iComplianceMonitorService;
        }
        Object LIZIZ2 = Lnj.LIZIZ(IComplianceMonitorService.class, false);
        if (LIZIZ2 != null) {
            IComplianceMonitorService iComplianceMonitorService2 = (IComplianceMonitorService) LIZIZ2;
            MethodCollector.o(480);
            return iComplianceMonitorService2;
        }
        if (Lnj.LLIIJLIL == null) {
            synchronized (IComplianceMonitorService.class) {
                try {
                    if (Lnj.LLIIJLIL == null) {
                        Lnj.LLIIJLIL = new ComplianceMonitorServiceImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(480);
                    throw th;
                }
            }
        }
        ComplianceMonitorServiceImpl complianceMonitorServiceImpl = (ComplianceMonitorServiceImpl) Lnj.LLIIJLIL;
        MethodCollector.o(480);
        return complianceMonitorServiceImpl;
    }

    public final InterfaceControlSettings LIZ() {
        List<InterfaceControlRule> rules;
        Set<String> value;
        MethodCollector.i(681);
        if (this.LIZIZ == null) {
            synchronized (this.LIZ) {
                try {
                    if (this.LIZIZ != null) {
                        InterfaceControlSettings interfaceControlSettings = this.LIZIZ;
                        return interfaceControlSettings;
                    }
                    String LIZIZ2 = LJII().LIZIZ();
                    this.LIZIZ = new InterfaceControlSettings((List) null, (String) null, (String) null, (Boolean) null, 15, (2HN) null);
                    Exception e = null;
                    if (36a.LIZ(LIZIZ2)) {
                        try {
                            this.LIZIZ = (InterfaceControlSettings) new Gson().LIZ(LIZIZ2, InterfaceControlSettings.class);
                            InterfaceControlSettings interfaceControlSettings2 = this.LIZIZ;
                            if (!(interfaceControlSettings2 == null || (rules = interfaceControlSettings2.getRules()) == null)) {
                                for (InterfaceControlRule ruleThens : rules) {
                                    List<RuleConfig> ruleThens2 = ruleThens.getRuleThens();
                                    if (ruleThens2 != null) {
                                        ArrayList arrayList = new ArrayList();
                                        for (T next : ruleThens2) {
                                            RuleConfig ruleConfig = (RuleConfig) next;
                                            if (n.LIZ((Object) ruleConfig.getType(), (Object) ConfigTypeEnum.PARAM_REPLACE.getType()) && (value = ruleConfig.getValue()) != null) {
                                                if (!value.isEmpty()) {
                                                    arrayList.add(next);
                                                }
                                            }
                                        }
                                        List<RuleConfig> list = arrayList;
                                        if (list != null) {
                                            for (RuleConfig ruleConfig2 : list) {
                                                Set<String> value2 = ruleConfig2.getValue();
                                                if (value2 != null) {
                                                    for (String LIZ2 : value2) {
                                                        List LIZ3 = z.LIZ(LIZ2, new String[]{":"}, 0, 6);
                                                        ruleConfig2.getReplaceMap().put(LIZ3.get(0), LIZ3.get(1));
                                                    }
                                                }
                                                Set<String> value3 = ruleConfig2.getValue();
                                                if (value3 != null) {
                                                    value3.clear();
                                                }
                                                Set<String> value4 = ruleConfig2.getValue();
                                                if (value4 != null) {
                                                    value4.addAll(ruleConfig2.getReplaceMap().keySet());
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        } catch (Exception e2) {
                            e = e2;
                        }
                    }
                    for (4A7 LIZ4 : this.LIZJ) {
                        LIZ4.LIZ(LIZIZ2, this.LIZIZ, e);
                    }
                } finally {
                    MethodCollector.o(681);
                }
            }
        }
        InterfaceControlSettings interfaceControlSettings3 = this.LIZIZ;
        MethodCollector.o(681);
        return interfaceControlSettings3;
    }

    public final void LIZ(49y r2) {
        M12.LIZ(r2);
        LJII().LIZ(r2);
    }

    public final void LIZ(4A7 r2) {
        M12.LIZ(r2);
        this.LIZJ.add(r2);
    }
}
