// ==================== 首页统计 Mock 数据 ====================

import { MockRequest } from './index';

/**
 * 获取首页统计数据
 * GET /deepseek/overview/topData
 */
export const mockFetchOverviewData = async () => {
    console.log('[Mock] 获取首页统计数据');

    // 模拟统计数据
    const stats = {
        // 核心指标
        totalApps: 18,           // 应用总数
        onlineApps: 14,          // 已上线应用
        auditingApps: 2,         // 审核中应用
        offlineApps: 2,          // 已下线应用

        // 知识库统计
        totalKnowledgeBases: 45,      // 知识库总数
        totalDocuments: 328,          // 文档总数
        totalSlices: 2156,            // 切片总数

        // 使用统计
        totalConversations: 12580,    // 总会话数
        todayConversations: 156,      // 今日会话数
        activeUsers: 89,              // 活跃用户数

        // 待办事项
        pendingAudits: 3,             // 待审核应用数
        pendingUpdates: 5,            // 待更新应用数

        // 趋势数据（最近 7 天）
        conversationTrend: [
            { date: '2026-03-27', count: 142 },
            { date: '2026-03-28', count: 158 },
            { date: '2026-03-29', count: 134 },
            { date: '2026-03-30', count: 189 },
            { date: '2026-03-31', count: 167 },
            { date: '2026-04-01', count: 201 },
            { date: '2026-04-02', count: 156 },
        ],

        // 应用分类统计
        categoryStats: [
            { category: 'professional', name: '专业知识', count: 7, percentage: 38.9 },
            { category: 'functional', name: '职能管理', count: 6, percentage: 33.3 },
            { category: 'project', name: '项目级应用', count: 5, percentage: 27.8 },
        ],

        // 热门应用 TOP5
        topApps: [
            { id: 'app_010', name: '客户服务知识库', conversations: 3200, trend: '+12%' },
            { id: 'app_007', name: '市场营销支持平台', conversations: 2100, trend: '+8%' },
            { id: 'app_005', name: '技术培训知识库', conversations: 1580, trend: '+15%' },
            { id: 'app_001', name: '合同审查助手', conversations: 1250, trend: '+5%' },
            { id: 'app_002', name: '人力资源问答机器人', conversations: 890, trend: '+3%' },
        ],

        // 最新动态
        recentActivities: [
            { id: 1, type: 'app_created', content: '新创建应用「知识产权助手」', user: '李十六', time: '10 分钟前' },
            { id: 2, type: 'app_updated', content: '更新应用「合同审查助手」知识库', user: '张三', time: '25 分钟前' },
            { id: 3, type: 'audit_approved', content: '通过应用「质量管理助手」审核', user: '管理员', time: '1 小时前' },
            { id: 4, type: 'app_published', content: '应用「档案管理助手」已上线', user: '孙十五', time: '2 小时前' },
            { id: 5, type: 'audit_rejected', content: '拒绝应用「合规管理助手」审核', user: '管理员', time: '3 小时前' },
        ],
    };

    return {
        code: 200,
        message: 'success',
        data: stats,
    };
};

/**
 * 获取在线用户数据
 * GET /deepseek/overview/onlineUserData
 */
export const mockFetchOnlineUserData = async () => {
    console.log('[Mock] 获取在线用户数据');

    return {
        code: 200,
        message: 'success',
        data: {
            onlineUsers: 89,
            peakToday: 156,
            peakTime: '14:30',
            avgOnlineTime: '45 分钟',
        },
    };
};

/**
 * 获取会话数据
 * GET /deepseek/overview/conversationData
 */
export const mockFetchConversationData = async (request: MockRequest) => {
    const { startDate, endDate } = request.params || {};

    console.log('[Mock] 获取会话数据', { startDate, endDate });

    return {
        code: 200,
        message: 'success',
        data: {
            total: 12580,
            today: 156,
            yesterday: 201,
            thisWeek: 1047,
            lastWeek: 892,
            growthRate: '+17.4%',
        },
    };
};

/**
 * 获取数据集列表
 * GET /deepseek/dataset/pageList
 */
export const mockFetchDatasetList = async (request: MockRequest) => {
    const { pageNum = 1, pageSize = 10, keyword } = request.data || {};

    console.log('[Mock] 获取数据集列表', { pageNum, pageSize, keyword });

    const datasets = [
        { id: 'ds_001', name: '法律法规数据集', docCount: 156, sliceCount: 892, updatedAt: '2026-04-01' },
        { id: 'ds_002', name: '技术规范数据集', docCount: 234, sliceCount: 1245, updatedAt: '2026-03-30' },
        { id: 'ds_003', name: '企业制度数据集', docCount: 89, sliceCount: 456, updatedAt: '2026-03-28' },
        { id: 'ds_004', name: '行业案例数据集', docCount: 312, sliceCount: 1678, updatedAt: '2026-03-25' },
        { id: 'ds_005', name: '产品知识数据集', docCount: 178, sliceCount: 934, updatedAt: '2026-03-22' },
    ];

    let filteredData = datasets;
    if (keyword) {
        filteredData = datasets.filter(d => d.name.toLowerCase().includes(keyword.toLowerCase()));
    }

    const total = filteredData.length;
    const startIndex = (pageNum - 1) * pageSize;
    const endIndex = startIndex + pageSize;
    const list = filteredData.slice(startIndex, endIndex);

    return {
        code: 200,
        message: 'success',
        data: {
            list,
            total,
            pageNum,
            pageSize,
        },
    };
};

// ==================== 导出所有 Mock 处理函数 ====================

export const overviewMockHandlers = {
    'GET /deepseek/overview/topData': mockFetchOverviewData,
    'GET /deepseek/overview/onlineUserData': mockFetchOnlineUserData,
    'GET /deepseek/overview/conversationData': mockFetchConversationData,
    'GET /deepseek/dataset/pageList': mockFetchDatasetList,
};
