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

import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.mes.bean.MesContainerPackageDetail;
import cn.estsh.i3plus.pojo.mes.bean.MesContainerSnStation;
import cn.estsh.i3plus.pojo.mes.bean.MesStation;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.io.Serializable;

/**
 * 生产过程上下文对象-容器条码上料明细
 */
@Data
public class MesContainerPackageDetailContext extends MesContainerPackageDetail implements Serializable {

    private static final long serialVersionUID = 3519172978836073435L;

    @ApiParam(name = "站点")
    private String station;

    @ApiParam("顺序号")
    private Integer seq;

    @ApiParam(value = "主表创建日期")
    private String createDatetime2Package;

    @ApiParam("库存数量")
    private Double remainQty;

    @ApiParam("库存KEY")
    private String remainKey;

    @ApiParam("缓存的库存数量")
    private Double remainQtyCached;

    @ApiParam("扣减数量")
    private Double deductionQty;

    @ApiParam(name = "设备代码")
    private String equipmentCode;

    @ApiParam(name = "站点类型")
    private Integer stationType;

    @ApiParam(name = "加工模式")
    private Integer processMethod;

    public MesContainerPackageDetailContext() {}

    public MesContainerPackageDetailContext(MesContainerPackageDetail containerPackageDetail) {
        BeanUtils.copyProperties(containerPackageDetail, this);
    }

    public MesContainerPackageDetailContext(MesContainerPackageDetailContext containerPackageDetailContext) {
        BeanUtils.copyProperties(containerPackageDetailContext, this);
    }

    public MesContainerPackageDetailContext containerSnStation(MesContainerSnStation containerSnStation) {
        this.station = containerSnStation.getStation();
        this.seq = !StringUtils.isEmpty(containerSnStation.getSeq()) ? containerSnStation.getSeq() : MesPcnExtConstWords.ZERO;
        this.createDatetime2Package = containerSnStation.getCreateDatetime();
        return this;
    }

    public MesContainerPackageDetailContext station(MesStation station) {
        this.equipmentCode = station.getEquipmentCode();
        this.stationType = station.getStationType();
        this.processMethod = station.getProcessMethod();
        return this;
    }

    public MesContainerPackageDetailContext remainQty(String remainQty) {
        return remainQty(!StringUtils.isEmpty(remainQty) ? new Double(remainQty) : new Double(MesPcnExtConstWords.ZERO));
    }

    public MesContainerPackageDetailContext remainQty(Double remainQty) {
        this.remainQty = remainQty;
        return this;
    }

    public MesContainerPackageDetailContext remainQtyCached(Double remainQtyCached) {
        this.remainQtyCached = remainQtyCached;
        return this;
    }

    public MesContainerPackageDetailContext deductionQty(Double deductionQty) {
        this.deductionQty = deductionQty;
        return this;
    }

    public MesContainerPackageDetailContext remainKey(String remainKey) {
        this.remainKey = remainKey;
        return this;
    }

    public MesStation getStationInfo() {
        MesStation station = new MesStation();
        station.setEquipmentCode(this.equipmentCode);
        station.setStationType(this.stationType);
        station.setProcessMethod(this.processMethod);
        return station;
    }

}
