package com.kexue.skills.entity.dto;

import com.kexue.skills.entity.PaymentOrder;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 订单状态DTO
 */
@Data
public class OrderStatusDto {
    
    @Schema(description = "订单ID")
    private Long orderId;
    
    @Schema(description = "订单号")
    private String orderNo;
    
    @Schema(description = "状态码")
    private Integer status;
    
    @Schema(description = "状态文本")
    private String statusText;
    
    @Schema(description = "支付金额")
    private BigDecimal amount;
    
    @Schema(description = "支付方式：1.微信 2.支付宝")
    private Integer payType;
    
    @Schema(description = "创建时间")
    private Date createTime;
    
    @Schema(description = "支付时间")
    private Date payTime;
    
    @Schema(description = "渠道订单号")
    private String channelOrderNo;
    
    /**
     * 从PaymentOrder构建OrderStatusDto
     * @param order 支付订单
     * @return 订单状态DTO
     */
    public static OrderStatusDto fromPaymentOrder(PaymentOrder order) {
        OrderStatusDto dto = new OrderStatusDto();
        dto.setOrderId(order.getOrderId());
        dto.setOrderNo(order.getOrderNo());
        dto.setStatus(order.getStatus());
        dto.setStatusText(getStatusText(order.getStatus()));
        dto.setAmount(order.getAmount());
        dto.setPayType(order.getPayType());
        dto.setCreateTime(order.getCreateTime());
        dto.setPayTime(order.getPayTime());
        dto.setChannelOrderNo(order.getChannelOrderNo());
        return dto;
    }
    
    /**
     * 获取状态文本
     * @param status 状态码
     * @return 状态文本
     */
    private static String getStatusText(Integer status) {
        switch (status) {
            case 1: return "待支付";
            case 2: return "已支付";
            case 3: return "支付失败";
            case 4: return "已取消";
            case 5: return "已退款";
            default: return "未知状态";
        }
    }
}