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 java.time.LocalDateTime;

/**
 * 积分消费相关DTO
 */
public class PointsConsumptionDto {

    /**
     * 积分余额响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "积分余额信息")
    public static class BalanceResponse {
        @Schema(description = "当前积分余额", example = "1500")
        private Integer currentPoints;

        @Schema(description = "积分过期时间", example = "2025-12-31T23:59:59")
        private LocalDateTime pointsExpiresAt;

        @Schema(description = "是否即将过期（30天内）", example = "false")
        private Boolean willExpireSoon;

        @Schema(description = "距离过期天数", example = "120")
        private Long daysUntilExpire;
    }

    /**
     * 积分消费记录响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "积分消费记录")
    public static class ConsumptionLogResponse {
        @Schema(description = "记录ID", example = "1")
        private Long id;

        @Schema(description = "关联任务编号", example = "TASK202510221234567890")
        private String taskNo;

        @Schema(description = "变动类型", example = "consume")
        private String changeType;

        @Schema(description = "变动类型名称", example = "消费")
        private String changeTypeName;

        @Schema(description = "变动积分数量（正数表示增加，负数表示减少）", example = "-10")
        private Integer changeAmount;

        @Schema(description = "变动前积分余额", example = "1510")
        private Integer balanceBefore;

        @Schema(description = "变动后积分余额", example = "1500")
        private Integer balanceAfter;

        @Schema(description = "变动描述", example = "AI图片生成消费")
        private String description;

        @Schema(description = "创建时间", example = "2025-10-22T10:30:00")
        private LocalDateTime createTime;
    }

    /**
     * 积分消费记录分页响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "积分消费记录分页结果")
    public static class ConsumptionLogPageResponse {
        @Schema(description = "记录列表")
        private java.util.List<ConsumptionLogResponse> records;

        @Schema(description = "总记录数", example = "100")
        private Long total;

        @Schema(description = "当前页码", example = "1")
        private Integer page;

        @Schema(description = "每页数量", example = "10")
        private Integer size;

        @Schema(description = "总页数", example = "10")
        private Integer totalPages;
        
        @Schema(description = "汇总数据")
        private SummaryData summary;
    }
    
    /**
     * 积分汇总数据
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "积分汇总数据")
    public static class SummaryData {
        @Schema(description = "当前可用积分", example = "1500")
        private Integer currentPoints;
        
        @Schema(description = "累计充值积分", example = "2000")
        private Integer totalRechargePoints;
        
        @Schema(description = "累计消耗积分（有效消费，排除已退款）", example = "500")
        private Integer totalConsumePoints;
        
        @Schema(description = "累计退回积分", example = "100")
        private Integer totalRefundPoints;
        
        @Schema(description = "积分过期时间", example = "2025-12-31T23:59:59")
        private LocalDateTime pointsExpiresAt;
    }

    /**
     * 积分统计响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "积分统计信息")
    public static class ConsumptionStatsResponse {
        @Schema(description = "当前积分余额", example = "1500")
        private Integer currentPoints;

        @Schema(description = "累计充值积分", example = "2000")
        private Integer totalRechargePoints;

        @Schema(description = "累计消费积分", example = "500")
        private Integer totalConsumePoints;

        @Schema(description = "累计退款积分", example = "0")
        private Integer totalRefundPoints;

        @Schema(description = "积分过期时间", example = "2025-12-31T23:59:59")
        private LocalDateTime pointsExpiresAt;
    }
}

