package com.ss.android.ugc.aweme.services;

import X.3hr;
import X.C0665KCq;
import X.C0722KEv;
import X.C4672Lnj;
import X.C4705LoG;
import X.KT7;
import X.M12;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.google.gson.Gson;
import com.ss.android.ugc.aweme.shortvideo.model.BusinessGoodsPublishModel;
import com.ss.android.ugc.aweme.shortvideo.model.BusinessGoodsPublishSetting;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import kotlin.h.b.n;

public final class BusinessGoodsServiceImpl implements IBusinessGoodsService {
    static {
        Covode.recordClassIndex(105036);
    }

    public final void clearCache() {
        C4705LoG.LIZ = null;
    }

    public final void removeUserSetting(String str) {
        M12.LIZ((Object) str);
        C4705LoG.LIZ(str);
    }

    public final List<C0665KCq> createBridges(KT7 kt7) {
        M12.LIZ((Object) kt7);
        return C0722KEv.LIZ.LIZ(kt7);
    }

    public final BusinessGoodsPublishModel getCurBusinessDraftModel(String str) {
        BusinessGoodsPublishModel businessGoodsPublishModel;
        M12.LIZ((Object) str);
        if (C4705LoG.LIZIZ() != null) {
            Iterator<BusinessGoodsPublishModel> it = C4705LoG.LIZ.getGoodsPublishModels().iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                businessGoodsPublishModel = it.next();
                if (businessGoodsPublishModel != null && TextUtils.equals(str, businessGoodsPublishModel.videoPath)) {
                    break;
                }
            }
            n.LIZIZ(businessGoodsPublishModel, "");
            return businessGoodsPublishModel;
        }
        businessGoodsPublishModel = null;
        n.LIZIZ(businessGoodsPublishModel, "");
        return businessGoodsPublishModel;
    }

    public static IBusinessGoodsService createIBusinessGoodsServicebyMonsterPlugin(boolean z) {
        MethodCollector.i(3911);
        IBusinessGoodsService iBusinessGoodsService = (IBusinessGoodsService) C4672Lnj.LIZ(IBusinessGoodsService.class, z);
        if (iBusinessGoodsService != null) {
            MethodCollector.o(3911);
            return iBusinessGoodsService;
        }
        Object LIZIZ = C4672Lnj.LIZIZ(IBusinessGoodsService.class, z);
        if (LIZIZ != null) {
            IBusinessGoodsService iBusinessGoodsService2 = (IBusinessGoodsService) LIZIZ;
            MethodCollector.o(3911);
            return iBusinessGoodsService2;
        }
        if (C4672Lnj.ao == null) {
            synchronized (IBusinessGoodsService.class) {
                try {
                    if (C4672Lnj.ao == null) {
                        C4672Lnj.ao = new BusinessGoodsServiceImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(3911);
                    throw th;
                }
            }
        }
        BusinessGoodsServiceImpl businessGoodsServiceImpl = (BusinessGoodsServiceImpl) C4672Lnj.ao;
        MethodCollector.o(3911);
        return businessGoodsServiceImpl;
    }

    public final void saveBusinessGoodsInfo(BusinessGoodsPublishModel businessGoodsPublishModel) {
        M12.LIZ((Object) businessGoodsPublishModel);
        BusinessGoodsPublishSetting LIZIZ = C4705LoG.LIZIZ();
        if (LIZIZ == null) {
            LIZIZ = new BusinessGoodsPublishSetting();
            LIZIZ.setUserId(BaseUserService.createIUserServicebyMonsterPlugin(false).getCurrentUserID());
        }
        List goodsPublishModels = LIZIZ.getGoodsPublishModels();
        if (goodsPublishModels == null) {
            goodsPublishModels = new ArrayList();
        } else {
            goodsPublishModels.remove(businessGoodsPublishModel);
        }
        if (businessGoodsPublishModel != null) {
            goodsPublishModels.add(businessGoodsPublishModel);
        }
        LIZIZ.setGoodsPublishModels(goodsPublishModels);
        List<BusinessGoodsPublishSetting> LIZ = C4705LoG.LIZ();
        LIZ.remove(LIZIZ);
        LIZ.add(LIZIZ);
        3hr.LIZ.LJ().LIZIZ(new Gson().LIZIZ(LIZ));
        C4705LoG.LIZ = LIZIZ;
    }
}
