package com.haha.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@TableName("t_order")
public class Order implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    /** 乐观锁版本号 */
    @Version
    @TableField(exist = false)
    private Integer version = 1;

    private String orderNo;

    private String orderName;

    private String outTradeNo;

    /** 哈哈平台订单号（ORDER回调返回，用于 syncPayStatusToHaha） */
    private String hahaOrderId;

    private String activityId;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long userId;

    private String deviceId;

    /** 订单总金额（原价） */
    private BigDecimal totalAmount;

    /** 订单优惠金额（营销活动优惠 + 优惠券优惠） */
    private BigDecimal discountAmount;

    /** 实付总金额 = total_amount - discount_amount */
    private BigDecimal paidAmount;

    private String payStatus;

    /** 支付方式 */
    private String payType;

    /** 支付渠道（wechat/alipay/alipay_credit/balance） */
    private String payChannel;

    /** 第三方支付平台交易号 */
    private String transactionId;

    /** 当前退款记录ID（关联 t_refund.id） */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long currentRefundId;

    private String videoUrl;

    private BigDecimal confidence;

    private String items;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime payTime;

    /** 退款状态 */
    private String refundStatus;

    /** 退款金额 */
    private BigDecimal refundAmount;

    /** 退款时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime refundTime;

    /** 退款原因 */
    private String refundReason;

    /** 支付分服务订单号（微信侧） */
    private String payScoreOrderId;

    /** 支付分订单状态: CREATED/DOING/USER_PAYING/DONE */
    private String payScoreState;

    /** 用户微信支付分分数值 */
    private Integer payScoreValue;

    /** 支付分扣款失败原因（扣款失败时记录微信返回的错误信息） */
    private String payScoreFailReason;

    /** 支付分服务ID */
    private String serviceId;

    /** 服务开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime serviceStartTime;

    /** 服务结束时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime serviceEndTime;

    private Integer status;

    /** 订单类型：OUT-拿出(正常消费)，IN-放入(异物放入) */
    private String orderType;

    @TableField(exist = false)
    private String statusLabel;

    @TableField(exist = false)
    private String payStatusLabel;

    @TableField(exist = false)
    private String userName;

    @TableField(exist = false)
    private String phone;

    @TableField(exist = false)
    private String deviceName;

    /** 门店名称快照（下单时写入，不受后续门店改名影响） */
    private String storeName;

    @TableField(exist = false)
    private String shopName;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long shopId;

    /** 用户消费标签：new-新用户, regular-老用户, frequent-常客 */
    @TableField(exist = false)
    private String userTag;

    /** 用户消费标签中文描述 */
    @TableField(exist = false)
    private String userTagLabel;
}
