package com.erp.dashboard.entity;

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

import java.time.LocalDateTime;

/**
 * 库存实体 - 用于Dashboard库存预警
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("stocks")
public class Stock {

    @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;

    @TableLogic
    private LocalDateTime deletedAt;

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

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

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