package com.dora.dto;

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

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户余额相关DTO
 */
public class UserBalanceDto {

    /**
     * 用户余额信息响应
     */
    @Data
    @Schema(description = "用户余额信息响应")
    public static class UserBalanceResponse {
        
        @Schema(description = "当前余额", example = "750.00")
        private BigDecimal balance;
        
        @Schema(description = "累计总收入", example = "1039.65")
        private BigDecimal totalIncome;
        
        @Schema(description = "累计提现总额", example = "150.00")
        private BigDecimal totalWithdrawn;
        
        @Schema(description = "审核中金额", example = "100.00")
        private BigDecimal frozenAmount;
        
        @Schema(description = "可用余额", example = "650.00")
        private BigDecimal availableBalance;
        
        @Schema(description = "昨日收益", example = "50.00")
        private BigDecimal yesterdayIncome;
        
        @Schema(description = "最后更新时间")
        private LocalDateTime lastUpdatedAt;
    }

    /**
     * 余额增加明细响应
     */
    @Data
    @Schema(description = "余额增加明细响应")
    public static class IncomeDetailResponse {
        
        @Schema(description = "推广收益", example = "139.65")
        private BigDecimal promotionIncome;
        
        @Schema(description = "推广收益明细列表")
        private List<PromotionIncomeItem> promotionIncomes;
        
        @Schema(description = "内容收益列表")
        private List<ContentIncomeItem> contentIncomes;
        
        @Schema(description = "总收益", example = "1039.65")
        private BigDecimal totalIncome;
    }

    /**
     * 推广收益项
     */
    @Data
    @Schema(description = "推广收益项")
    public static class PromotionIncomeItem {
        
        @Schema(description = "分成记录ID", example = "1")
        private Long commissionId;
        
        @Schema(description = "订单号", example = "ORD202508291129069049")
        private String orderNo;
        
        @Schema(description = "订单金额", example = "39.00")
        private BigDecimal orderAmount;
        
        @Schema(description = "粉丝用户ID", example = "17564379418669007")
        private Long fanUserId;
        
        @Schema(description = "粉丝用户名", example = "用户704254")
        private String fanUsername;
        
        @Schema(description = "推广等级", example = "1")
        private Integer commissionLevel;
        
        @Schema(description = "推广等级名称", example = "Lv1")
        private String levelName;
        
        @Schema(description = "分成比例", example = "0.30")
        private BigDecimal commissionRate;
        
        @Schema(description = "分成金额", example = "11.70")
        private BigDecimal commissionAmount;
        
        @Schema(description = "分成时间")
        private LocalDateTime commissionTime;
        
        @Schema(description = "结算时间")
        private LocalDateTime settledAt;
        
        @Schema(description = "收益描述", example = "【推广收益】粉丝 用户张三 购买会员获得Lv1推广分成 - 订单金额39.00元，分成11.70元(30.0%)")
        private String description;
    }

    /**
     * 内容收益项
     */
    @Data
    @Schema(description = "内容收益项")
    public static class ContentIncomeItem {
        
        @Schema(description = "内容类型", example = "workflow", allowableValues = {"workflow", "video"})
        private String contentType;
        
        @Schema(description = "内容类型名称", example = "工作流")
        private String contentTypeName;
        
        @Schema(description = "内容ID", example = "1")
        private Long contentId;
        
        @Schema(description = "内容名称", example = "智能图像生成工作流")
        private String contentName;
        
        @Schema(description = "收益金额", example = "250.00")
        private BigDecimal incomeAmount;
        
        @Schema(description = "收益时间")
        private LocalDateTime incomeTime;
        
        @Schema(description = "收益描述", example = "【视频收益】AI基础教程 达到视频等级1阶段奖励 - 观看次数达到1000次，获得50.00元收益")
        private String description;
    }

    /**
     * 余额变动记录响应
     */
    @Data
    @Schema(description = "余额变动记录响应")
    public static class BalanceLogResponse {
        
        @Schema(description = "变动记录列表")
        private List<BalanceLogItem> records;
        
        @Schema(description = "总记录数", example = "10")
        private Long total;
        
        @Schema(description = "当前页码", example = "1")
        private Integer page;
        
        @Schema(description = "每页大小", example = "10")
        private Integer size;
    }

    /**
     * 余额变动记录项
     */
    @Data
    @Schema(description = "余额变动记录项")
    public static class BalanceLogItem {
        
        @Schema(description = "记录ID", example = "1")
        private Long id;
        
        @Schema(description = "变动类型", example = "income", allowableValues = {"income", "withdraw", "freeze", "unfreeze"})
        private String changeType;
        
        @Schema(description = "变动类型名称", example = "收入")
        private String changeTypeName;
        
        @Schema(description = "变动金额", example = "100.00")
        private BigDecimal changeAmount;
        
        @Schema(description = "变动前余额", example = "650.00")
        private BigDecimal balanceBefore;
        
        @Schema(description = "变动后余额", example = "750.00")
        private BigDecimal balanceAfter;
        
        @Schema(description = "来源类型", example = "promotion", allowableValues = {"promotion", "workflow", "video", "withdraw", "adjustment"})
        private String sourceType;
        
        @Schema(description = "来源类型名称", example = "推广收益")
        private String sourceTypeName;
        
        @Schema(description = "来源ID", example = "1")
        private Long sourceId;
        
        @Schema(description = "变动描述", example = "推广收益结算")
        private String description;
        
        @Schema(description = "创建时间")
        private LocalDateTime createTime;
    }

    /**
     * 余额变动类型枚举
     */
    public static class ChangeType {
        public static final String INCOME = "income";
        public static final String WITHDRAW = "withdraw";
        public static final String FREEZE = "freeze";
        public static final String UNFREEZE = "unfreeze";
        
        public static String getChangeTypeName(String changeType) {
            switch (changeType) {
                case INCOME: return "收入";
                case WITHDRAW: return "提现";
                case FREEZE: return "冻结";
                case UNFREEZE: return "解冻";
                default: return "未知";
            }
        }
    }

    /**
     * 来源类型枚举
     */
    public static class SourceType {
        public static final String PROMOTION = "promotion";
        public static final String WORKFLOW = "workflow";
        public static final String VIDEO = "video";
        public static final String WITHDRAW = "withdraw";
        public static final String ADJUSTMENT = "adjustment";
        
        public static String getSourceTypeName(String sourceType) {
            switch (sourceType) {
                case PROMOTION: return "推广收益";
                case WORKFLOW: return "工作流收益";
                case VIDEO: return "视频收益";
                case WITHDRAW: return "提现";
                case ADJUSTMENT: return "余额调整";
                default: return "未知";
            }
        }
    }
} 