// Mock数据 - 用于开发和测试
import { OrderStatus, TravelStatus } from './types.js'

// Mock用户数据
export const mockUsers = [
  {
    id: 1,
    username: 'user1',
    nickname: '旅行爱好者',
    avatar: '/static/user/avatar1.jpg',
    phone: '138****1234',
    points: 150,
    level: 2,
    createTime: '2024-01-15'
  },
  {
    id: 2,
    username: 'user2',
    nickname: '动物保护者',
    avatar: '/static/user/avatar2.jpg',
    email: 'user2@jiebanke.com',
    points: 300,
    level: 3,
    createTime: '2024-02-20'
  }
]

// Mock轮播图数据
export const mockBanners = [
  {
    id: 1,
    image: '/static/banners/banner1.jpg',
    title: '西藏之旅',
    link: '/pages/travel/list',
    type: 'travel'
  },
  {
    id: 2,
    image: '/static/banners/banner2.jpg',
    title: '动物认养',
    link: '/pages/animal/list',
    type: 'animal'
  },
  {
    id: 3,
    image: '/static/banners/banner3.jpg',
    title: '鲜花配送',
    link: '/pages/flower/list',
    type: 'flower'
  }
]

// Mock旅行计划数据
export const mockTravelPlans = [
  {
    id: 1,
    title: '西藏拉萨深度游',
    destination: '西藏拉萨',
    coverImage: '/static/travel/tibet.jpg',
    startDate: '2024-10-01',
    endDate: '2024-10-07',
    budget: 5000,
    currentMembers: 3,
    maxMembers: 6,
    description: '探索西藏神秘文化，感受高原风情',
    status: TravelStatus.RECRUITING,
    creator: mockUsers[0],
    createTime: '2024-08-20'
  },
  {
    id: 2,
    title: '云南大理休闲游',
    destination: '云南大理',
    coverImage: '/static/travel/yunnan.jpg',
    startDate: '2024-10-05',
    endDate: '2024-10-12',
    budget: 3500,
    currentMembers: 2,
    maxMembers: 4,
    description: '漫步古城，享受洱海风光',
    status: TravelStatus.RECRUITING,
    creator: mockUsers[1],
    createTime: '2024-08-22'
  }
]

// Mock动物数据
export const mockAnimals = [
  {
    id: 1,
    name: '小羊驼',
    species: '羊驼',
    price: 1000,
    image: '/static/animals/alpaca.jpg',
    description: '温顺可爱的羊驼，适合家庭认养',
    location: '西藏牧场',
    isHot: true,
    status: 'available',
    createTime: '2024-08-15'
  },
  {
    id: 2,
    name: '小绵羊',
    species: '绵羊',
    price: 800,
    image: '/static/animals/sheep.jpg',
    description: '毛茸茸的小绵羊，非常温顺',
    location: '内蒙古草原',
    isHot: false,
    status: 'available',
    createTime: '2024-08-18'
  }
]

// Mock花束数据
export const mockFlowers = [
  {
    id: 1,
    name: '浪漫玫瑰',
    description: '11朵红玫瑰，象征热烈的爱情',
    price: 199,
    image: '/static/flowers/rose.jpg',
    category: '爱情',
    stock: 50,
    createTime: '2024-08-10'
  },
  {
    id: 2,
    name: '向日葵花束',
    description: '9朵向日葵，象征阳光和希望',
    price: 179,
    image: '/static/flowers/sunflower.jpg',
    category: '祝福',
    stock: 30,
    createTime: '2024-08-12'
  }
]

// Mock订单数据
export const mockOrders = [
  {
    id: 'ORD202408270001',
    orderNo: '202408270001',
    type: 'travel',
    title: '西藏拉萨深度游',
    image: '/static/travel/tibet.jpg',
    price: 5000,
    count: 1,
    totalAmount: 5000,
    status: OrderStatus.UNPAID,
    createTime: '2024-08-27 10:00:00'
  },
  {
    id: 'ORD202408270002',
    orderNo: '202408270002',
    type: 'animal',
    title: '小羊驼认养',
    image: '/static/animals/alpaca.jpg',
    price: 1000,
    count: 1,
    totalAmount: 1000,
    status: OrderStatus.PAID,
    createTime: '2024-08-27 11:30:00',
    payTime: '2024-08-27 11:35:00'
  }
]

// Mock系统公告
export const mockNotices = [
  {
    id: 1,
    title: '系统维护通知',
    content: '系统将于今晚进行维护，预计耗时2小时',
    type: 'system',
    isActive: true,
    createTime: '2024-08-26'
  },
  {
    id: 2,
    title: '新功能上线',
    content: '送花服务正式上线，欢迎体验',
    type: 'feature',
    isActive: true,
    createTime: '2024-08-27'
  }
]

// Mock API响应
export const mockResponses = {
  // 成功响应
  success: (data, message = '操作成功') => ({
    code: 0,
    message,
    data,
    timestamp: Date.now()
  }),

  // 错误响应
  error: (code, message) => ({
    code,
    message,
    timestamp: Date.now()
  }),

  // 分页响应
  pagination: (list, total, page = 1, pageSize = 10) => ({
    code: 0,
    message: '操作成功',
    data: {
      list,
      total,
      page,
      pageSize,
      totalPages: Math.ceil(total / pageSize)
    },
    timestamp: Date.now()
  })
}

// Mock服务函数
export const mockService = {
  // 模拟延迟
  delay: (ms = 500) => new Promise(resolve => setTimeout(resolve, ms)),

  // 模拟登录
  mockLogin: async (username, password) => {
    await mockService.delay(1000)
    
    if (username === 'admin' && password === '123456') {
      return mockResponses.success({
        token: 'mock-token-123456',
        refreshToken: 'mock-refresh-token-123456',
        userInfo: mockUsers[0]
      })
    }
    
    return mockResponses.error(1001, '用户名或密码错误')
  },

  // 模拟获取首页数据
  mockHomeData: async () => {
    await mockService.delay(800)
    return mockResponses.success({
      banners: mockBanners,
      travelPlans: mockTravelPlans,
      animals: mockAnimals,
      flowers: mockFlowers,
      notices: mockNotices
    })
  },

  // 模拟获取列表数据
  mockList: async (type, page = 1, pageSize = 10) => {
    await mockService.delay(600)
    
    const allData = {
      travel: mockTravelPlans,
      animal: mockAnimals,
      flower: mockFlowers,
      order: mockOrders
    }
    
    const data = allData[type] || []
    const start = (page - 1) * pageSize
    const end = start + pageSize
    const paginatedData = data.slice(start, end)
    
    return mockResponses.pagination(paginatedData, data.length, page, pageSize)
  },

  // 模拟获取详情
  mockDetail: async (type, id) => {
    await mockService.delay(500)
    
    const allData = {
      travel: mockTravelPlans,
      animal: mockAnimals,
      flower: mockFlowers,
      order: mockOrders
    }
    
    const data = allData[type] || []
    const item = data.find(item => item.id === id || item.id === parseInt(id))
    
    if (item) {
      return mockResponses.success(item)
    }
    
    return mockResponses.error(404, '数据不存在')
  }
}

// 导出所有Mock数据
export default {
  mockUsers,
  mockBanners,
  mockTravelPlans,
  mockAnimals,
  mockFlowers,
  mockOrders,
  mockNotices,
  mockResponses,
  mockService
}

// 使用示例
/*
// 在开发环境中使用Mock数据
if (process.env.NODE_ENV === 'development') {
  // 可以在这里替换真实的API调用
}
*/