package com.wms_main.model.vo.wms;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.wms_main.model.po.TAppInventory;
import com.wms_main.model.po.TAppInventoryRecord;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

/**
 * 盘点记录Vo
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class InventoryRecordVo {
    /**
     * 盘点id
     */
    @JsonProperty("inventoryId")
    private String inventoryId;
    /**
     * 料号
     */
    @JsonProperty("goodsId")
    private String goodsId;
    /**
     * 载具号
     */
    @JsonProperty("vehicleId")
    private String vehicleId;
    /**
     * 库存数量
     * 只记录盘点确认时间点
     */
    @JsonProperty("stockNum")
    private Integer stockNum;
    /**
     * 确认数量
     */
    @JsonProperty("confirmNum")
    private Integer confirmNum;
    /**
     * 盘点站台
     */
    @JsonProperty("invStand")
    private String invStand;
    /**
     * 盘点人
     */
    @JsonProperty("invUser")
    private String invUser;
    /**
     * 盘点类型：1：明盘；2：盲盘
     */
    @JsonProperty("invType")
    private Integer invType;
    /**
     * 盘点状态
     * 0. 初始化
     * 1. 已解析
     * 2. 已确认
     */
    @JsonProperty("invStatus")
    private Integer invStatus;
    /**
     * 盘点结果
     * -1: 盘亏
     * 0: 正常
     * 1: 盘盈
     */
    @JsonProperty("invResult")
    private Integer invResult;
    /**
     * 盘点任务创建时间
     */
    @JsonProperty("invCreateTime")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime invCreateTime;
    /**
     * 盘点确认时间
     */
    @JsonProperty("invConfirmTime")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime invConfirmTime;
    /**
     * 这个字段用于合并哪些任务是同一时间下发的
     */
    @JsonProperty("invOrderId")
    private String invOrderId;

    /**
     * 将盘点请求的Po转化为Vo
     * @param inventoryPo 请求Po
     * @return 盘点Vo
     */
    public static InventoryRecordVo ofTaskPo(TAppInventory inventoryPo) {
        if (inventoryPo == null) {
            return new InventoryRecordVo();
        }
        return new InventoryRecordVo(
                inventoryPo.getInventoryId(),
                inventoryPo.getGoodsId(),
                inventoryPo.getVehicleId(),
                inventoryPo.getStockNum(),
                inventoryPo.getConfirmNum(),
                inventoryPo.getInvStand(),
                inventoryPo.getInvUser(),
                inventoryPo.getInvType(),
                inventoryPo.getInvStatus(),
                inventoryPo.getInvResult(),
                inventoryPo.getInvCreateTime(),
                inventoryPo.getInvConfirmTime(),
                inventoryPo.getInvOrderId()
        );
    }

    /**
     * 将盘点记录的Po转化为Vo
     * @param inventoryRecordPo 盘点记录Po
     * @return 盘点记录Vo
     */
    public static InventoryRecordVo ofRecordPo(TAppInventoryRecord inventoryRecordPo) {
        if (inventoryRecordPo == null) {
            return new InventoryRecordVo();
        }
        return new InventoryRecordVo(
                inventoryRecordPo.getInventoryId(),
                inventoryRecordPo.getGoodsId(),
                inventoryRecordPo.getVehicleId(),
                inventoryRecordPo.getStockNum(),
                inventoryRecordPo.getConfirmNum(),
                inventoryRecordPo.getInvStand(),
                inventoryRecordPo.getInvUser(),
                inventoryRecordPo.getInvType(),
                inventoryRecordPo.getInvStatus(),
                inventoryRecordPo.getInvResult(),
                inventoryRecordPo.getInvCreateTime(),
                inventoryRecordPo.getInvConfirmTime(),
                inventoryRecordPo.getInvOrderId()
        );
    }
}
