package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.rulematch;

import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesEquipVariableCfgRuleMatchDispatchService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesEquipVariableCfgCollectContext;
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext;
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Primary
@Service
public class MesEquipVariableCfgRuleMatchDispatchService implements IMesEquipVariableCfgRuleMatchDispatchService {

    private Object matchEquipVariableCfgCollectContext(StationRequestBean reqBean, MesProductionProcessContext productionProcessContext, String variableCategory, List<MesEquipVariableCfgCollectContext> collectContextList, String strategyClass) {
        return ((IMesEquipVariableCfgRuleMatchDispatchService) SpringContextsUtil.getBean(strategyClass)).matchEquipVariableCfgCollectContext(reqBean, productionProcessContext, variableCategory, collectContextList);
    }

    @Override
    public Object matchEquipVariableCfgCollectContext(StationRequestBean reqBean, MesProductionProcessContext productionProcessContext, String variableCategory, List<MesEquipVariableCfgCollectContext> collectContextList) {

        switch (MesExtEnumUtil.EQUIP_VARIABLE_CFG_CATEGORY.getByValue(variableCategory)) {

            case PRODUCT_OK:
            case PRODUCT_NOK:
            case PRODUCT_SCRAP:
            case PRODUCT_SUSPICIOUS:
            case READY_SIGNAL:
            case MEMBRANE_SIGNAL:
            case BYPASS:
                return matchEquipVariableCfgCollectContext(reqBean, productionProcessContext, variableCategory, collectContextList, "mesEvcRuleMatchCompareValueService");
            case FIRST_MOULD_NO:
            case MOULD_NO:
            case ASSEMBLY:
            case PRODUCT_SN:
            case WORK_ORDER:
            case PRODUCTION_PART_NO:
            case RECYCLABLE_PACKAGE:
                return matchEquipVariableCfgCollectContext(reqBean, productionProcessContext, variableCategory, collectContextList, "mesEvcRuleMatchBackValueService");

            //TODO CASE 数据变量接口逻辑根据变量类别实现策略

            default:
                return false;

        }

    }

}
