// Mock数据管理
export const mockData = {
  // 用户信息
  userInfo: {
    id: '1001',
    name: '测试用户',
    avatar: 'https://wx.qlogo.cn/mmopen/vi_32/SYiaibeiaiaV2RiaU9cEJWV6KibjBjEia9TQ15b4mSxVj0xIibN6k2Lb3w6HlYw/132',
    wechatScore: 650,
    balance: 100
  },
  
  // 商品列表
  products: [
    {
      id: '1',
      name: '可口可乐',
      price: 3.5,
      stock: 20,
      image: 'https://img.yzcdn.cn/vant/apple-1.jpg'
    },
    {
      id: '2',
      name: '雪碧',
      price: 3.5,
      stock: 15,
      image: 'https://img.yzcdn.cn/vant/apple-2.jpg'
    },
    {
      id: '3',
      name: '矿泉水',
      price: 2,
      stock: 30,
      image: 'https://img.yzcdn.cn/vant/apple-3.jpg'
    },
    {
      id: '4',
      name: '红牛',
      price: 6,
      stock: 10,
      image: 'https://img.yzcdn.cn/vant/apple-4.jpg'
    }
  ],
  
  // 订单列表
  orders: [
    {
      id: 'order_001',
      status: 'completed',
      amount: 7,
      products: [
        { id: '1', name: '可口可乐', price: 3.5, quantity: 2 }
      ],
      createTime: '2026-01-23 10:30:00',
      videoUrl: 'https://example.com/video1.mp4'
    },
    {
      id: 'order_002',
      status: 'pending',
      amount: 3.5,
      products: [
        { id: '2', name: '雪碧', price: 3.5, quantity: 1 }
      ],
      createTime: '2026-01-23 09:15:00',
      videoUrl: 'https://example.com/video2.mp4'
    }
  ],
  
  // 设备信息
  deviceInfo: {
    id: 'device_001',
    name: '测试设备',
    status: 'online',
    location: '北京市朝阳区',
    stockRate: 85
  }
};

// Mock API 类型定义
interface MockResponse<T> {
  success: boolean;
  data: T;
}

// Mock API 函数
export const mockApi = {
  // 获取用户信息
  getUserInfo: (): Promise<MockResponse<typeof mockData.userInfo>> => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({ success: true, data: mockData.userInfo });
      }, 300);
    });
  },
  
  // 获取商品列表
  getProducts: () => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({ success: true, data: mockData.products });
      }, 300);
    });
  },
  
  // 获取订单列表
  getOrders: () => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({ success: true, data: mockData.orders });
      }, 300);
    });
  },
  
  // 获取设备信息
  getDeviceInfo: () => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({ success: true, data: mockData.deviceInfo });
      }, 300);
    });
  },
  
  // 扫码开门
  scanDoor: (code: string) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({ 
          success: true, 
          data: { 
            doorOpened: true, 
            message: '开门成功',
            deviceId: 'device_001'
          }
        });
      }, 500);
    });
  },
  
  // 关门结算
  closeDoor: (deviceId: string) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({ 
          success: true, 
          data: { 
            orderId: 'order_' + Date.now(),
            amount: 7,
            products: [
              { id: '1', name: '可口可乐', price: 3.5, quantity: 2 }
            ],
            status: 'completed'
          }
        });
      }, 2000);
    });
  }
};
