/**
 * 用户列表模拟数据
 */

import type { User } from '../admin/user'
import type { PageResponse } from '../config'

const users: User[] = [
  {
    id: 1,
    username: 'zhangsan',
    realName: '张三',
    email: 'zhangsan@example.com',
    phone: '13800138001',
    position: '销售经理',
    department: '销售部',
    role: '管理员',
    status: 'active',
    lastLoginTime: '2024-03-15 10:30:00',
    createTime: '2024-01-10 09:00:00'
  },
  {
    id: 2,
    username: 'lisi',
    realName: '李四',
    email: 'lisi@example.com',
    phone: '13800138002',
    position: '销售专员',
    department: '销售部',
    role: '学员',
    status: 'active',
    lastLoginTime: '2024-03-15 09:15:00',
    createTime: '2024-01-15 14:20:00'
  },
  {
    id: 3,
    username: 'wangwu',
    realName: '王五',
    email: 'wangwu@example.com',
    phone: '13800138003',
    position: '前端开发',
    department: '技术部',
    role: '学员',
    status: 'pending',
    lastLoginTime: '',
    createTime: '2024-02-01 11:30:00'
  },
  {
    id: 4,
    username: 'zhaoliu',
    realName: '赵六',
    email: 'zhaoliu@example.com',
    phone: '13800138004',
    position: '后端开发',
    department: '技术部',
    role: '讲师',
    status: 'active',
    lastLoginTime: '2024-03-14 16:45:00',
    createTime: '2024-01-20 10:00:00'
  },
  {
    id: 5,
    username: 'qianqi',
    realName: '钱七',
    email: 'qianqi@example.com',
    phone: '13800138005',
    position: '测试工程师',
    department: '技术部',
    role: '学员',
    status: 'inactive',
    lastLoginTime: '2024-02-28 14:20:00',
    createTime: '2024-01-25 15:30:00'
  }
]

// 生成更多模拟数据
for (let i = 6; i <= 50; i++) {
  users.push({
    id: i,
    username: `user${i}`,
    realName: `用户${i}`,
    email: `user${i}@example.com`,
    phone: `1380013${8000 + i}`,
    position: ['销售专员', '技术支持', '客服专员', '产品经理'][i % 4],
    department: ['销售部', '技术部', '客服部', '产品部'][i % 4],
    role: ['学员', '讲师', '管理员'][i % 3],
    status: ['active', 'inactive', 'pending'][i % 3] as any,
    lastLoginTime: i % 3 === 0 ? '' : new Date(Date.now() - Math.random() * 7 * 24 * 60 * 60 * 1000).toLocaleString('zh-CN'),
    createTime: new Date(Date.now() - Math.random() * 60 * 24 * 60 * 60 * 1000).toLocaleString('zh-CN')
  })
}

// 模拟分页、搜索和筛选
const mockData = (params?: any): PageResponse<User> => {
  const { page = 1, pageSize = 10, keyword = '', status = '', role = '' } = params || {}
  
  // 筛选
  let filteredList = users
  
  // 关键词搜索
  if (keyword) {
    filteredList = filteredList.filter(item => 
      item.username.includes(keyword) || 
      item.realName.includes(keyword) ||
      item.email.includes(keyword) ||
      item.phone.includes(keyword)
    )
  }
  
  // 状态筛选
  if (status) {
    filteredList = filteredList.filter(item => item.status === status)
  }
  
  // 角色筛选
  if (role) {
    filteredList = filteredList.filter(item => item.role === role)
  }
  
  // 分页
  const start = (page - 1) * pageSize
  const end = start + pageSize
  const list = filteredList.slice(start, end)
  
  return {
    list,
    total: filteredList.length,
    page,
    pageSize
  }
}

export default mockData
