// 初始化示例数据
import { MachineryRecord, MachineryTag } from '../types/machinery';
import { machineryStorage } from './machineryStorage';
import { initializeMaintenanceMockData } from './maintenanceMockData';
import { initializeChangeHistoryMockData } from './changeHistoryMockData';

export function initializeMockData() {
  // 检查是否已有数据
  const existingMachinery = machineryStorage.getAllMachinery();
  if (existingMachinery.length > 0) {
    // 已有农机数据，但可能没有维护记录和变更历史，尝试初始化
    initializeMaintenanceMockData();
    initializeChangeHistoryMockData();
    return;
  }

  // 初始化标签
  const mockTags: MachineryTag[] = [
    { id: 'tag-1', name: '重点设备', color: '#ef4444', createdAt: '2025-01-01T00:00:00.000Z' },
    { id: 'tag-2', name: '高效节能', color: '#10b981', createdAt: '2025-01-01T00:00:00.000Z' },
    { id: 'tag-3', name: '进口设备', color: '#3b82f6', createdAt: '2025-01-01T00:00:00.000Z' },
    { id: 'tag-4', name: '需保养', color: '#f59e0b', createdAt: '2025-01-01T00:00:00.000Z' },
  ];

  mockTags.forEach(tag => machineryStorage.saveTag(tag));

  // 初始化农机档案
  const mockMachinery: MachineryRecord[] = [
    {
      id: 'machinery-1',
      name: '约翰迪尔6B-1404拖拉机',
      model: '6B-1404',
      category: '耕地机械',
      usage: '旱地',
      manufacturer: '约翰迪尔（天津）有限公司',
      manufactureDate: '2024-03-15',
      purchaseDate: '2024-04-01',
      engineNumber: 'JD20240315001',
      chassisNumber: 'JDTJ2024040001',
      power: '103',
      weight: '4200',
      workingWidth: '2.8',
      purchasePrice: 350000,
      supplier: '天津农机销售公司',
      invoiceNumber: 'INV-2024-001',
      insuranceCompany: '中国人民财产保险',
      insurancePolicyNumber: 'PICC-2024-001',
      insuranceStartDate: '2024-04-01',
      insuranceEndDate: '2025-03-31',
      insuranceAmount: 300000,
      status: '正常',
      currentLocation: '1号地块',
      operator: '张三',
      department: '第一生产队',
      maintenanceCycle: 3,
      maintenanceCycleUnit: 'month',
      remarks: '主力耕作设备，状态良好',
      tags: ['tag-1', 'tag-2'],
      qrCode: 'machinery-1',
      createdAt: '2024-04-01T08:00:00.000Z',
      updatedAt: '2024-04-01T08:00:00.000Z',
      createdBy: '系统管理员',
      updatedBy: '系统管理员',
    },
    {
      id: 'machinery-2',
      name: '久保田PRO688Q收割机',
      model: 'PRO688Q',
      category: '收获机械',
      usage: '水田',
      manufacturer: '久保田农业机械（苏州）有限公司',
      manufactureDate: '2024-05-20',
      purchaseDate: '2024-06-01',
      engineNumber: 'KB20240520001',
      chassisNumber: 'KBSZ2024060001',
      power: '68',
      weight: '2850',
      workingWidth: '2.0',
      purchasePrice: 280000,
      supplier: '苏州农机经销商',
      invoiceNumber: 'INV-2024-002',
      insuranceCompany: '太平洋保险',
      insurancePolicyNumber: 'CPIC-2024-002',
      insuranceStartDate: '2024-06-01',
      insuranceEndDate: '2025-05-31',
      insuranceAmount: 250000,
      status: '正常',
      currentLocation: '机库A区',
      operator: '李四',
      department: '第二生产队',
      maintenanceCycle: 50,
      maintenanceCycleUnit: 'day',
      remarks: '水稻收割专用，效率高',
      tags: ['tag-2', 'tag-3'],
      qrCode: 'machinery-2',
      createdAt: '2024-06-01T08:00:00.000Z',
      updatedAt: '2024-06-01T08:00:00.000Z',
      createdBy: '系统管理员',
      updatedBy: '系统管理员',
    },
    {
      id: 'machinery-3',
      name: '丰疆智能无人播种机',
      model: 'FJ-BS2024',
      category: '播种机械',
      usage: '通用',
      manufacturer: '丰疆智能科技股份有限公司',
      manufactureDate: '2024-02-10',
      purchaseDate: '2024-03-01',
      engineNumber: 'FJ20240210001',
      chassisNumber: 'FJZN2024030001',
      power: '45',
      weight: '1500',
      workingWidth: '3.0',
      purchasePrice: 180000,
      supplier: '智能农机专营店',
      invoiceNumber: 'INV-2024-003',
      insuranceCompany: '中国人寿保险',
      insurancePolicyNumber: 'CLIC-2024-003',
      insuranceStartDate: '2024-03-01',
      insuranceEndDate: '2025-02-28',
      insuranceAmount: 150000,
      status: '待维护',
      currentLocation: '维修车间',
      operator: '王五',
      department: '第一生产队',
      maintenanceCycle: 1,
      maintenanceCycleUnit: 'month',
      remarks: '智能播种，需要定期校准',
      tags: ['tag-2', 'tag-4'],
      qrCode: 'machinery-3',
      createdAt: '2024-03-01T08:00:00.000Z',
      updatedAt: '2024-03-01T08:00:00.000Z',
      createdBy: '系统管理员',
      updatedBy: '系统管理员',
    },
    {
      id: 'machinery-4',
      name: '大疆T40植保无人机',
      model: 'T40',
      category: '植保机械',
      usage: '通用',
      manufacturer: '深圳大疆创新科技有限公司',
      manufactureDate: '2024-01-15',
      purchaseDate: '2024-02-01',
      engineNumber: 'DJI20240115001',
      chassisNumber: 'DJISZ2024020001',
      power: '电动',
      weight: '50',
      workingWidth: '7.0',
      purchasePrice: 58000,
      supplier: '大疆农业授权经销商',
      invoiceNumber: 'INV-2024-004',
      insuranceCompany: '平安保险',
      insurancePolicyNumber: 'PINGAN-2024-004',
      insuranceStartDate: '2024-02-01',
      insuranceEndDate: '2025-01-31',
      insuranceAmount: 50000,
      status: '正常',
      currentLocation: '5号地块',
      operator: '赵六',
      department: '植保组',
      maintenanceCycle: 15,
      maintenanceCycleUnit: 'day',
      remarks: '高效植保，续航40分钟',
      tags: ['tag-1', 'tag-2', 'tag-3'],
      qrCode: 'machinery-4',
      createdAt: '2024-02-01T08:00:00.000Z',
      updatedAt: '2024-02-01T08:00:00.000Z',
      createdBy: '系统管理员',
      updatedBy: '系统管理员',
    },
    {
      id: 'machinery-5',
      name: '雷沃欧豹1604拖拉机',
      model: '1604',
      category: '耕地机械',
      usage: '旱地',
      manufacturer: '雷沃重工股份有限公司',
      manufactureDate: '2023-11-20',
      purchaseDate: '2023-12-01',
      engineNumber: 'LW20231120001',
      chassisNumber: 'LWSD2023120001',
      power: '118',
      weight: '4800',
      workingWidth: '3.2',
      purchasePrice: 320000,
      supplier: '山东农机销售中心',
      invoiceNumber: 'INV-2023-088',
      insuranceCompany: '中国人民财产保险',
      insurancePolicyNumber: 'PICC-2023-088',
      insuranceStartDate: '2023-12-01',
      insuranceEndDate: '2024-11-30',
      insuranceAmount: 280000,
      status: '正常',
      currentLocation: '3号地块',
      operator: '孙七',
      department: '第三生产队',
      maintenanceCycle: 6,
      maintenanceCycleUnit: 'month',
      remarks: '国产品牌，性价比高',
      tags: ['tag-2'],
      qrCode: 'machinery-5',
      createdAt: '2023-12-01T08:00:00.000Z',
      updatedAt: '2023-12-01T08:00:00.000Z',
      createdBy: '系统管理员',
      updatedBy: '系统管理员',
    },
  ];

  mockMachinery.forEach(machinery => machineryStorage.saveMachinery(machinery));
  
  // 初始化维护记录示例数据
  initializeMaintenanceMockData();
  
  // 初始化变更历史示例数据
  initializeChangeHistoryMockData();
  
  console.log('✅ 农机档案、维护记录和变更历史示例数据初始化完成');
}
