package com.erp.report.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import java.time.LocalDateTime;

/**
 * 库存统计实体
 * 对应数据库表：stocks
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("stocks")
public class StockEntity {

    @TableId(type = IdType.AUTO)
    private Long id;

    private String skuCode;
    
    private String skuName;
    
    private Long warehouseId;
    
    private Integer quantity;
    
    private Integer lockedQuantity;
    
    private Integer reservedQuantity;
    
    private Integer defectiveQuantity;
    
    private Integer warningThreshold;
    
    private Integer version;

    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;

    @TableLogic
    private LocalDateTime deletedAt;

    /**
     * 计算可用库存
     */
    public Integer getAvailableQuantity() {
        return quantity - lockedQuantity - reservedQuantity - defectiveQuantity;
    }
}
