/**
 * Mock数据 - 签到功能
 */

import { CheckinType } from '@/api/checkin';

interface LocationInfo {
  latitude: number;
  longitude: number;
  address: string;
  accuracy: number;
}

interface CheckinPhoto {
  id: string;
  path: string;
  watermarkPath?: string;
  timestamp: number;
  location: LocationInfo;
}

interface CheckinRecord {
  id: string;
  type: CheckinType;
  typeName: string;
  userId: number;
  userName: string;
  userNo: string;
  shopId?: number;
  shopName?: string;
  deviceId?: number;
  deviceName?: string;
  location: LocationInfo;
  photos: CheckinPhoto[];
  remark: string;
  status: 'pending' | 'synced' | 'failed';
  createdAt: string;
  syncedAt?: string;
  offlineId?: string;
}

interface CheckinStats {
  todayCount: number;
  weekCount: number;
  monthCount: number;
  inventoryTallyCount: number;
  deliveryReplenishCount: number;
  pendingSyncCount: number;
}

interface TodayCheckin {
  hasInventoryTally: boolean;
  hasDeliveryReplenish: boolean;
  inventoryTallyTime?: string;
  deliveryReplenishTime?: string;
}

const createMockLocation = (): LocationInfo => ({
  latitude: 31.2304 + Math.random() * 0.01,
  longitude: 121.4737 + Math.random() * 0.01,
  address: '上海市浦东新区张江高科技园区',
  accuracy: 65
});

const createMockPhoto = (index: number): CheckinPhoto => ({
  id: `photo_${Date.now()}_${index}`,
  path: '/static/mock/photo.jpg',
  watermarkPath: '/static/mock/photo_watermark.jpg',
  timestamp: Date.now() - index * 60000,
  location: createMockLocation()
});

export const mockCheckinRecords: CheckinRecord[] = [
  {
    id: 'checkin_001',
    type: CheckinType.INVENTORY_TALLY,
    typeName: '理货盘点签到',
    userId: 1,
    userName: '张三',
    userNo: 'EMP001',
    shopId: 1,
    shopName: '张江科技园店',
    deviceId: 101,
    deviceName: '1号充电桩',
    location: createMockLocation(),
    photos: [createMockPhoto(0), createMockPhoto(1)],
    remark: '库存盘点正常，无异常',
    status: 'synced',
    createdAt: '2026-02-28 09:30:00',
    syncedAt: '2026-02-28 09:30:05'
  },
  {
    id: 'checkin_002',
    type: CheckinType.DELIVERY_REPLENISH,
    typeName: '补货确认签到',
    userId: 2,
    userName: '李四',
    userNo: 'EMP002',
    shopId: 2,
    shopName: '陆家嘴金融城店',
    deviceId: 201,
    deviceName: '2号充电桩',
    location: createMockLocation(),
    photos: [createMockPhoto(0)],
    remark: '补货完成，已补充矿泉水10瓶',
    status: 'synced',
    createdAt: '2026-02-28 10:15:00',
    syncedAt: '2026-02-28 10:15:03'
  },
  {
    id: 'checkin_003',
    type: CheckinType.INVENTORY_TALLY,
    typeName: '理货盘点签到',
    userId: 1,
    userName: '张三',
    userNo: 'EMP001',
    shopId: 3,
    shopName: '金桥开发区店',
    location: createMockLocation(),
    photos: [createMockPhoto(0), createMockPhoto(1), createMockPhoto(2)],
    remark: '发现部分商品临期，需要处理',
    status: 'synced',
    createdAt: '2026-02-27 14:20:00',
    syncedAt: '2026-02-27 14:20:08'
  },
  {
    id: 'checkin_004',
    type: CheckinType.DELIVERY_REPLENISH,
    typeName: '补货确认签到',
    userId: 3,
    userName: '王五',
    userNo: 'EMP003',
    shopId: 1,
    shopName: '张江科技园店',
    deviceId: 102,
    deviceName: '2号充电桩',
    location: createMockLocation(),
    photos: [createMockPhoto(0)],
    remark: '',
    status: 'synced',
    createdAt: '2026-02-27 16:45:00',
    syncedAt: '2026-02-27 16:45:02'
  },
  {
    id: 'checkin_005',
    type: CheckinType.INVENTORY_TALLY,
    typeName: '理货盘点签到',
    userId: 2,
    userName: '李四',
    userNo: 'EMP002',
    shopId: 2,
    shopName: '陆家嘴金融城店',
    location: createMockLocation(),
    photos: [createMockPhoto(0)],
    remark: '盘点完毕，库存充足',
    status: 'pending',
    createdAt: '2026-02-26 11:00:00',
    offlineId: 'offline_001'
  },
  {
    id: 'checkin_006',
    type: CheckinType.DELIVERY_REPLENISH,
    typeName: '补货确认签到',
    userId: 1,
    userName: '张三',
    userNo: 'EMP001',
    shopId: 4,
    shopName: '世纪公园店',
    deviceId: 301,
    deviceName: '1号充电桩',
    location: createMockLocation(),
    photos: [createMockPhoto(0), createMockPhoto(1)],
    remark: '补货完成',
    status: 'synced',
    createdAt: '2026-02-25 09:00:00',
    syncedAt: '2026-02-25 09:00:04'
  },
  {
    id: 'checkin_007',
    type: CheckinType.INVENTORY_TALLY,
    typeName: '理货盘点签到',
    userId: 3,
    userName: '王五',
    userNo: 'EMP003',
    shopId: 5,
    shopName: '世纪大道店',
    location: createMockLocation(),
    photos: [createMockPhoto(0)],
    remark: '正常',
    status: 'synced',
    createdAt: '2026-02-24 15:30:00',
    syncedAt: '2026-02-24 15:30:02'
  },
  {
    id: 'checkin_008',
    type: CheckinType.DELIVERY_REPLENISH,
    typeName: '补货确认签到',
    userId: 2,
    userName: '李四',
    userNo: 'EMP002',
    shopId: 3,
    shopName: '金桥开发区店',
    deviceId: 302,
    deviceName: '2号充电桩',
    location: createMockLocation(),
    photos: [createMockPhoto(0)],
    remark: '已补充零食和饮料',
    status: 'synced',
    createdAt: '2026-02-23 10:00:00',
    syncedAt: '2026-02-23 10:00:03'
  }
];

export const mockCheckinStats: CheckinStats = {
  todayCount: 2,
  weekCount: 8,
  monthCount: 35,
  inventoryTallyCount: 18,
  deliveryReplenishCount: 17,
  pendingSyncCount: 1
};

export const mockTodayCheckin: TodayCheckin = {
  hasInventoryTally: true,
  hasDeliveryReplenish: false,
  inventoryTallyTime: '2026-02-28 09:30:00'
};
