package com.emotion.dto.response;

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

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 仪表盘统计数据响应
 * 
 * @author system
 * @date 2025-10-31
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "仪表盘统计数据响应")
public class DashboardStatsResponse {

    @Schema(description = "用户统计")
    private UserStats userStats;

    @Schema(description = "内容统计")
    private ContentStats contentStats;

    @Schema(description = "AI服务统计")
    private AiServiceStats aiServiceStats;

    @Schema(description = "系统统计")
    private SystemStats systemStats;

    @Schema(description = "最近活动")
    private List<RecentActivity> recentActivities;

    @Schema(description = "数据更新时间")
    private LocalDateTime updateTime;

    @Schema(description = "用户增长趋势数据")
    private List<UserGrowthTrend> userGrowthTrends;

    @Schema(description = "最近登录用户")
    private List<RecentLogin> recentLogins;

    /**
     * 用户统计
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "用户统计")
    public static class UserStats {
        @Schema(description = "总用户数")
        private Long totalUsers;

        @Schema(description = "今日新增用户")
        private Long todayNewUsers;

        @Schema(description = "活跃用户数")
        private Long activeUsers;

        @Schema(description = "访客用户数")
        private Long guestUsers;
    }

    /**
     * 内容统计
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "内容统计")
    public static class ContentStats {
        @Schema(description = "总对话数")
        private Long totalConversations;

        @Schema(description = "总消息数")
        private Long totalMessages;

        @Schema(description = "日记帖子数")
        private Long diaryPosts;

        @Schema(description = "社区帖子数")
        private Long communityPosts;

        @Schema(description = "情绪记录数")
        private Long emotionRecords;
    }

    /**
     * AI服务统计
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "AI服务统计")
    public static class AiServiceStats {
        @Schema(description = "总API调用次数")
        private Long totalApiCalls;

        @Schema(description = "今日API调用次数")
        private Long todayApiCalls;

        @Schema(description = "成功调用次数")
        private Long successfulCalls;

        @Schema(description = "失败调用次数")
        private Long failedCalls;

        @Schema(description = "平均响应时间(ms)")
        private Double avgResponseTime;

        @Schema(description = "AI配置数量")
        private Long aiConfigCount;
    }

    /**
     * 系统统计
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "系统统计")
    public static class SystemStats {
        @Schema(description = "管理员数量")
        private Long adminCount;

        @Schema(description = "成就数量")
        private Long achievementCount;

        @Schema(description = "奖励数量")
        private Long rewardCount;

        @Schema(description = "系统运行时间")
        private String uptime;
    }

    /**
     * 最近活动
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "最近活动")
    public static class RecentActivity {
        @Schema(description = "活动类型")
        private String type;

        @Schema(description = "活动描述")
        private String description;

        @Schema(description = "用户ID")
        private String userId;

        @Schema(description = "用户名")
        private String username;

        @Schema(description = "活动时间")
        private LocalDateTime activityTime;

        @Schema(description = "额外数据")
        private Map<String, Object> extraData;
    }

    /**
     * 用户增长趋势
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "用户增长趋势")
    public static class UserGrowthTrend {
        @Schema(description = "日期")
        private String date;

        @Schema(description = "新增用户数")
        private Long newUsers;

        @Schema(description = "累计用户数")
        private Long totalUsers;
    }

    /**
     * 最近登录用户
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "最近登录用户")
    public static class RecentLogin {
        @Schema(description = "用户ID")
        private String userId;

        @Schema(description = "用户名")
        private String username;

        @Schema(description = "昵称")
        private String nickname;

        @Schema(description = "头像")
        private String avatar;

        @Schema(description = "登录时间")
        private LocalDateTime loginTime;

        @Schema(description = "登录时间描述")
        private String timeDescription;
    }
}