package com.dora.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import jakarta.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 积分充值相关DTO
 */
public class PointsRechargeDto {

    /**
     * 积分套餐响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "积分套餐信息")
    public static class PackageResponse {
        @Schema(description = "套餐ID", example = "1")
        private Long id;

        @Schema(description = "套餐名称", example = "标准包")
        private String name;

        @Schema(description = "套餐描述", example = "日常使用推荐")
        private String description;

        @Schema(description = "基础积分", example = "500")
        private Integer points;

        @Schema(description = "赠送积分", example = "50")
        private Integer bonusPoints;

        @Schema(description = "总积分", example = "550")
        private Integer totalPoints;

        @Schema(description = "价格", example = "48.00")
        private BigDecimal price;

        @Schema(description = "原价", example = "50.00")
        private BigDecimal originalPrice;

        @Schema(description = "积分有效期（天）", example = "365")
        private Integer pointsExpireDays;

        @Schema(description = "优惠标签", example = "赠送50积分")
        private String discountLabel;

        @Schema(description = "是否热门", example = "true")
        private Boolean isHot;

        @Schema(description = "是否上架", example = "true")
        private Boolean isActive;
    }

    /**
     * 创建充值订单请求
     */
    @Data
    @Schema(description = "创建积分充值订单请求")
    public static class CreateRechargeOrderRequest {
        @NotNull(message = "套餐ID不能为空")
        @Schema(description = "套餐ID", example = "2", required = true)
        private Long packageId;

        @NotNull(message = "支付方式不能为空")
        @Schema(description = "支付方式（1-支付宝/2-微信支付）", example = "2", required = true)
        private Integer paymentMethod;

        @Schema(description = "是否使用余额抵扣", example = "false")
        private Boolean useBalance = false;
        
        @Schema(description = "微信用户OpenID（微信支付JSAPI必填）", example = "o6_bmjrPTlm6_2sgVt7hMZOPfL2M")
        private String openid;
        
        @Schema(description = "交易类型（JSAPI-小程序/APP-APP支付）", example = "JSAPI")
        private String tradeType = "JSAPI";
    }

    /**
     * 创建充值订单响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "创建积分充值订单响应")
    public static class CreateRechargeOrderResponse {
        @Schema(description = "订单号", example = "ORD20251021123456")
        private String orderNo;

        @Schema(description = "订单金额", example = "48.00")
        private BigDecimal amount;

        @Schema(description = "积分数量", example = "550")
        private Integer pointsAmount;

        @Schema(description = "支付方式", example = "2")
        private Integer paymentMethod;

        @Schema(description = "支付参数（用于调起支付）")
        private String paymentParams;

        @Schema(description = "创建时间")
        private LocalDateTime createTime;
    }

    /**
     * 充值记录响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "积分充值记录")
    public static class RechargeRecordResponse {
        @Schema(description = "订单号", example = "ORD20251021123456")
        private String orderNo;

        @Schema(description = "套餐名称", example = "标准包")
        private String packageName;

        @Schema(description = "充值积分", example = "550")
        private Integer pointsAmount;

        @Schema(description = "支付金额", example = "48.00")
        private BigDecimal amount;

        @Schema(description = "支付方式", example = "微信支付")
        private String paymentMethodName;

        @Schema(description = "订单状态", example = "已完成")
        private String statusName;

        @Schema(description = "创建时间")
        private LocalDateTime createTime;

        @Schema(description = "支付时间")
        private LocalDateTime paidAt;
    }

    /**
     * 充值统计响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "积分充值统计")
    public static class RechargeStatsResponse {
        @Schema(description = "总充值次数", example = "10")
        private Long totalRechargeCount;

        @Schema(description = "总充值金额", example = "500.00")
        private BigDecimal totalAmount;

        @Schema(description = "总充值积分", example = "6000")
        private Long totalPoints;

        @Schema(description = "是否首次充值", example = "false")
        private Boolean isFirstRecharge;

        @Schema(description = "最后充值时间")
        private LocalDateTime lastRechargeTime;
    }
}

