package cn.estsh.i3plus.ext.mes.pcn.pojo.context;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 生产过程上下文对象-设备LOG采集处理对象
 */
@Data
public class MesEquipLogDispatchContext implements Serializable {

    private static final long serialVersionUID = 917933189935264321L;

    @ApiParam("组织代码")
    private String organizeCode;

    @ApiParam("是否采集到数据")
    private Boolean isCollectValue = false;

    @ApiParam("是否常变值")
    private Boolean needNewValue = false;

    @ApiParam("数据变量接口逻辑信息集合")
    private List<MesEquipVariableCfgCollectContext> equipVariableCfgCollectContextList;

    @ApiParam("需要重置设备LOG表ID集合")
    private Map<Long, String> resetEquipmentLogIdMap;

    public MesEquipLogDispatchContext() {}

    public MesEquipLogDispatchContext(String organizeCode) {
        this.organizeCode = organizeCode;
    }

    public MesEquipLogDispatchContext isCollectValue() {
        this.isCollectValue = true;
        return this;
    }

    public MesEquipLogDispatchContext needNewValue() {
        this.needNewValue = true;
        return this;
    }

    public MesEquipLogDispatchContext equipVariableCfgCollectContextList(List<MesEquipVariableCfgCollectContext> equipVariableCfgCollectContextList) {
        this.equipVariableCfgCollectContextList = equipVariableCfgCollectContextList;
        return this;
    }

    public MesEquipLogDispatchContext resetEquipmentLogIdMap(Map<Long, String> equipmentLogIdMap) {
        if (CollectionUtils.isEmpty(equipmentLogIdMap)) return this;
        if (CollectionUtils.isEmpty(this.resetEquipmentLogIdMap)) this.resetEquipmentLogIdMap = new HashMap<>();
        this.resetEquipmentLogIdMap.putAll(equipmentLogIdMap);
        return this;
    }

}
