package com.wms.entity.app.request;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.wms.entity.app.dto.extend.StockDetailInfo;
import com.wms.entity.table.Stock;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 库存查询请求
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class StockQuery extends PageQuery {
    /**
     * 库存编号
     */
    @JsonProperty("stockId")
    private String stockId;
    /**
     * 库位ID
     */
    @JsonProperty("locationId")
    private String locationId;
    /**
     * 托盘号
     */
    @JsonProperty("vehicleId")
    private String vehicleId;
    /**
     * 重量
     */
    @JsonProperty("weight")
    private BigDecimal weight;
    /**
     * 库存状态
     * 正常、出库中、锁定 等
     */
    @JsonProperty("stockStatus")
    private Integer stockStatus;
    /**
     * 创建时间
     */
    @JsonProperty("createTime")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    /**
     * 最后更新时间
     */
    @JsonProperty("lastUpdateTime")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastUpdateTime;
    /**
     * 最后更新用户
     */
    @JsonProperty("lastUpdateUser")
    private String lastUpdateUser;
    /**
     * 是否盘点
     */
    @JsonProperty("isInventory")
    private Integer isInventory;
    /**
     * 盘点任务号   盘点出库和盘点入库同样
     */
    @JsonProperty("inventoryTaskId")
    private String inventoryTaskId;
    /**
     * 呆滞天数
     */
    @JsonProperty("noUseDays")
    private Integer noUseDays;
    /**
     * 物料编号
     */
    @JsonProperty("goodsId")
    private String goodsId;
    /**
     * 物料名称
     */
    @JsonProperty("goodsName")
    private String goodsName;
    /**
     * 物料状态
     */
    @JsonProperty("goodsStatus")
    private Integer goodsStatus;
    /**
     * 剩余数量
     */
    @JsonProperty("remainNum")
    private BigDecimal remainNum;
    /**
     * 入库库存总数
     */
    @JsonProperty("totalNum")
    private BigDecimal totalNum;

    /**
     * 转化为库存Po
     * @return 转化结果
     */
    public Stock toStockPo() {
        Stock stockPo = new Stock();
        stockPo.setStockId(this.stockId);
        stockPo.setLocationId(this.locationId);
        stockPo.setVehicleId(this.vehicleId);
        stockPo.setWeight(this.weight);
        stockPo.setStockStatus(this.stockStatus);
        stockPo.setCreateTime(this.createTime);
        stockPo.setLastUpdateTime(this.lastUpdateTime);
        stockPo.setLastUpdateUser(this.lastUpdateUser);
        stockPo.setIsInventory(this.isInventory);
        stockPo.setInventoryTaskId(this.inventoryTaskId);
        stockPo.setNoUseDays(this.noUseDays);
        StockDetailInfo goodsRelated = new StockDetailInfo();
        goodsRelated.setGoodsId(this.goodsId);
        goodsRelated.setGoodsName(this.goodsName);
        goodsRelated.setGoodsStatus(this.goodsStatus);
        goodsRelated.setRemainNum(this.remainNum);
        goodsRelated.setTotalNum(this.totalNum);
        stockPo.setGoodsRelated(goodsRelated);
        return stockPo;
    }
}
