package com.xisc.pm.api.dto;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hzero.core.base.BaseConstants;

import com.xisc.pm.domain.entity.PmPdRuleSet;
import com.xisc.pm.infra.enums.PdRuleItemType;
import com.xisc.pm.infra.enums.PdRuleSetType;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 规则库参数
 * @author jun.zeng
 *
 * @param <T> 调用规则库的请求参数
 * 
 */
@Data
public class RuleParamDTO implements Serializable{
    
    private static final long serialVersionUID = 237376769379939479L;

    public RuleParamDTO(PdRuleSetType pdRuleSetType){
        this.ruleSetNo = pdRuleSetType.getCode();
    }
    
    @ApiModelProperty("校验失败结果是否通过异常抛出")
    private boolean throwCheckExceptionFlag = true;
    
    @ApiModelProperty("业务参数")
    private Map<String , Object> bizData ;
    
    @ApiModelProperty("规则集号")
    private String ruleSetNo ;
    
    @ApiModelProperty("规则库号")
    private Long ruleNo;
    
    @ApiModelProperty("无须执行的规则")
    private Set<Long> excludeRuleNo = new HashSet<>();
    
    @ApiModelProperty("规则集数据缓存")
    private Map<String , List<PmPdRuleSet>> pmPdRuleSetMap = new HashMap<String, List<PmPdRuleSet>>();
    
    @ApiModelProperty("租户ID")
    private Long tenantId ;
    
    public void buildExcludeRuleNo(PmProContFilterRequestDTO pmProContYield) {
        if(pmProContYield != null) {
            if(pmProContYield.getRuleNoSTFlag() != null &&
                    BaseConstants.Flag.NO.longValue() == pmProContYield.getRuleNoSTFlag().longValue()) {
                // 热处理模式匹配标志
                excludeRuleNo.add(PdRuleItemType.HEAT_TREAT_MODE.getCode());
            }
            if(pmProContYield.getRuleNoSXFlag() != null &&
                    BaseConstants.Flag.NO.longValue() == pmProContYield.getRuleNoSXFlag().longValue()) {
                // 超声探伤要求匹配标志
                excludeRuleNo.add(PdRuleItemType.ULT_DETECT_METHOD_AND_ULT_STG.getCode());
            }
        }
    }
}
