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

import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentSpotCheck;
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentSpotCheckDetail;
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentSpotCheckPart;
import com.alibaba.fastjson.JSONObject;
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.List;

/**
 * 设备点检上下文
 */
@Data
public class MesEquipSpotCheckContext implements Serializable {

    private static final long serialVersionUID = -5475187758845705565L;

    @ApiParam("是否存在设备点检数据")
    private String isExistSpot = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValueStr();

    //不包含加工前类型的主表数据
    @ApiParam("设备点检主数据主表([Json]MesEquipmentSpotCheck)")
    private String equipmentSpotCheckJson;

    //仅包含全部点检类型主表ID对应的自动类型的明细数据
    @ApiParam("设备点检主数据明细表([Json]List<MesEquipmentSpotCheckDetail>)")
    private String equipmentSpotCheckDetailJson;

    @ApiParam("设备点检主数据关联零件表([Json]MesEquipmentSpotCheckPart)")
    private String equipmentSpotCheckPartJson;

    //上下文赋值存在设备点检数据
    public MesEquipSpotCheckContext isExistSpot() {
        this.isExistSpot = CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr();
        return this;
    }

    //从上下文中取出设备点检主数据主表集合
    public List<MesEquipmentSpotCheck> getEquipmentSpotCheckList() {
        return !StringUtils.isEmpty(this.equipmentSpotCheckJson) ? JSONObject.parseArray(this.equipmentSpotCheckJson, MesEquipmentSpotCheck.class) : null;
    }

    //从上下文中取出设备点检主数据明细表集合
    public List<MesEquipmentSpotCheckDetail> getEquipmentSpotCheckDetailList() {
        return !StringUtils.isEmpty(this.equipmentSpotCheckDetailJson) ? JSONObject.parseArray(this.equipmentSpotCheckDetailJson, MesEquipmentSpotCheckDetail.class) : null;
    }

    //从上下文中取出设备点检主数据关联零件表集合
    public List<MesEquipmentSpotCheckPart> getEquipmentSpotCheckPartList() {
        return !StringUtils.isEmpty(this.equipmentSpotCheckPartJson) ? JSONObject.parseArray(this.equipmentSpotCheckPartJson, MesEquipmentSpotCheckPart.class) : null;
    }

    //上下文赋值设备点检主数据主表集合
    public MesEquipSpotCheckContext equipmentSpotCheckJson(List<MesEquipmentSpotCheck> equipmentSpotCheckList) {
        if (CollectionUtils.isEmpty(equipmentSpotCheckList)) return this;
        this.equipmentSpotCheckJson = JSONObject.toJSONString(equipmentSpotCheckList);
        return this;
    }

    //上下文赋值设备点检主数据明细表集合
    public MesEquipSpotCheckContext equipmentSpotCheckDetailJson(List<MesEquipmentSpotCheckDetail> equipmentSpotCheckDetailList) {
        if (CollectionUtils.isEmpty(equipmentSpotCheckDetailList)) return this;
        this.equipmentSpotCheckDetailJson = JSONObject.toJSONString(equipmentSpotCheckDetailList);
        return this;
    }

    //上下文赋值设备点检主数据关联零件表集合
    public MesEquipSpotCheckContext equipmentSpotCheckPartJson(List<MesEquipmentSpotCheckPart> equipmentSpotCheckPartList) {
        if (CollectionUtils.isEmpty(equipmentSpotCheckPartList)) return this;
        this.equipmentSpotCheckPartJson = JSONObject.toJSONString(equipmentSpotCheckPartList);
        return this;
    }

}
