package com.czg.order.entity;

import cn.hutool.core.util.StrUtil;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 订单详情 实体类。
 *
 * @author ww
 * @since 2025-02-14
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_order_detail")
public class OrderDetail implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Id(keyType = KeyType.Auto)
    private Long id;

    private Long orderId;

    private Long shopId;

    private Long productId;

    private String productImg;

    private String productName;

    /**
     * 商品类型：单规格商品  single 多规格商品 sku 套餐商品 package 称重商品 weigh 团购券 coupon
     */
    private String productType;

    private Long skuId;

    private String skuName;

    /**
     * 原价
     */
    private BigDecimal price;
    /**
     * 会员价
     */
    private BigDecimal memberPrice;
    /**
     * 临时改价/临时菜价
     */
    private BigDecimal discountSaleAmount;
    /**
     * 最终单价
     */
    private BigDecimal unitPrice;
    /**
     * 是否赠送 0否 1是
     */
    private Integer isGift;
    private boolean isUrgent;

    /**
     * 折扣金额(商品优惠券抵扣金额)
     */
    private BigDecimal discountAmount;

    /**
     * 打包费（单价）
     */
    private BigDecimal packAmount;

    /**
     * 支付金额，去除优惠券优惠金额的商品金额  不包含打包费
     */
    private BigDecimal payAmount;

    /**
     * 已退款金额
     */
    private BigDecimal returnAmount;

    /**
     * 数量
     */
    private BigDecimal num;

    /**
     * 打包数量
     */
    private BigDecimal packNumber;
    /**
     * 优惠券抵扣数量
     */
    private BigDecimal couponNum;
    /**
     * 半价券抵扣数量
     */
    private BigDecimal halfPriceCouponNum;

    /**
     * 退菜数量（不管价格）
     */
    private BigDecimal returnNum;

    /**
     * 退单数量
     */
    private BigDecimal refundNum;

    /**
     * 退款单号
     */
    private String refundNo;

    /**
     * 临时改价备注
     */
    private String discountSaleNote;

    /**
     * 状态: in-production 制作中;wait_out 待取餐;refunding 退款中; part_refund 部分退单; refund-退单; done 完成;
     */
    private String status;
    /**
     * 菜品状态：待起菜 PENDING_PREP 待出菜 READY_TO_SERVE 已出菜 SENT_OUT  已上菜 DELIVERED
     */
    private String subStatus;

    /**
     * 当前下单次数
     */
    private Integer placeNum;
    /**
     * 是否参加限时折扣
     */
    private Integer isTimeDiscount;
    /**
     * 是否是临时菜品
     */
    private Integer isTemporary;

    /**
     * 是否打票
     */
    private Integer isPrint;

    /**
     * 是否等叫
     */
    private Integer isWaitCall;
    @Column(ignore = true)
    private Integer isAutoSoldStock;

    /**
     * 套餐商品选择信息
     */
    private String proGroupInfo;

    /**
     * 备注
     */
    private String remark;

    /**
     * 退款备注
     */
    private String refundRemark;

    @Column(onInsertValue = "now()")
    private LocalDateTime createTime;

    @Column(onInsertValue = "now()", onUpdateValue = "now()")
    private LocalDateTime updateTime;
    /**
     * 下单时间 为订单支付成功时间
     */
    private LocalDateTime orderTime;
    /**
     * 起菜时间
     */
    private LocalDateTime startOrderTime;
    /**
     * 出菜时间
     */
    private LocalDateTime dishOutTime;
    /**
     * 上菜时间
     */
    private LocalDateTime foodServeTime;

    public BigDecimal getRefundNum() {
        return refundNum == null ? BigDecimal.ZERO : refundNum;
    }

    public BigDecimal getReturnAmount() {
        return returnAmount == null ? BigDecimal.ZERO : returnAmount;
    }

    public BigDecimal getReturnNum() {
        return returnNum == null ? BigDecimal.ZERO : returnNum;
    }

    public BigDecimal getPackAmount() {
        return packAmount == null ? BigDecimal.ZERO : packAmount;
    }

    public BigDecimal getDiscountAmount() {
        return discountAmount == null ? BigDecimal.ZERO : discountAmount;
    }

    public String getRefundRemark() {
        return StrUtil.isBlank(refundRemark) ? "" : refundRemark + " ";
    }

    public BigDecimal getCouponNum() {
        return couponNum == null ? BigDecimal.ZERO : couponNum;
    }
}
