package com.erp.order.settlement.entity;

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

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

/**
 * 订单结算实体
 * 记录每笔订单的结算信息
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("order_settlement")
public class OrderSettlement {

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

    /** 结算单号 */
    private String settlementNo;

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

    /** 订单短ID */
    private String orderShortId;

    /** 平台订单号 */
    private String platformOrderSn;

    /** 平台编码 */
    private String platform;

    /** 店铺ID */
    private Long shopId;

    /** 店铺名称 */
    private String shopName;

    /** 订单金额（商品金额） */
    private BigDecimal orderAmount;

    /** 优惠金额 */
    private BigDecimal discountAmount;

    /** 运费 */
    private BigDecimal freight;

    /** 订单总金额 */
    private BigDecimal totalAmount;

    /** 平台服务费/佣金 */
    private BigDecimal platformFee;

    /** 平台佣金率 */
    private BigDecimal platformCommissionRate;

    /** 实际结算金额（订单总金额 - 平台佣金） */
    private BigDecimal settlementAmount;

    /** 结算状态: pending-待结算, calculating-计算中, settled-已结算, frozen-已冻结 */
    private String settlementStatus;

    /** 结算周期ID */
    private Long settlementPeriodId;

    /** 结算日期 */
    private LocalDateTime settlementDate;

    /** 支付时间 */
    private LocalDateTime paymentTime;

    /** 发货时间 */
    private LocalDateTime deliveryTime;

    /** 确认收货时间 */
    private LocalDateTime confirmTime;

    /** 结算确认时间 */
    private LocalDateTime confirmSettlementTime;

    /** 备注 */
    private String remark;

    /** 租户ID */
    private Long tenantId;

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

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

    @TableLogic
    private LocalDateTime deletedAt;

    /** 结算状态常量 */
    public static final String STATUS_PENDING = "pending";
    public static final String STATUS_CALCULATING = "calculating";
    public static final String STATUS_SETTLED = "settled";
    public static final String STATUS_FROZEN = "frozen";
}
