package com.erp.warehouse.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Builder;

import java.time.LocalDateTime;

/**
 * 库存流水日志实体
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("stock_log")
public class StockLog {

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

    /** SKU编码 */
    private String skuCode;

    /** 仓库ID */
    private Long warehouseId;

    /** 变更类型: inbound/outbound/lock/unlock/reserve/confirm/cancel/ship/defective_inbound/adjust */
    private String changeType;

    /** 变更前库存 */
    private Integer beforeQuantity;

    /** 变更数量（正数增加，负数减少） */
    private Integer changeQuantity;

    /** 变更后库存 */
    private Integer afterQuantity;

    /** 关联订单ID */
    private Long orderId;

    /** 关联单号（采购单号/销售单号等） */
    private String relatedNo;

    /** 运单号 */
    private String deliveryNo;

    /** 备注 */
    private String remark;

    /** 操作人ID */
    private Long operatorId;

    /** 创建时间 */
    private LocalDateTime createTime;

    /**
     * 获取类型标签
     */
    public String getTypeLabel() {
        return switch (changeType) {
            case "inbound" -> "入库";
            case "outbound" -> "出库";
            case "lock" -> "占用";
            case "unlock" -> "释放占用";
            case "reserve" -> "预扣";
            case "confirm" -> "确认预扣";
            case "cancel" -> "取消预扣";
            case "ship" -> "发货出库";
            case "defective_inbound" -> "残次品入库";
            case "adjust" -> "手动调整";
            default -> changeType;
        };
    }
}
