const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const SmartHost = require('../models/SmartHost');

// 测试数据
const testData = [
  {
    hostId: 'HOST-2023-001',
    name: '智能主机001',
    ipAddress: '192.168.1.101',
    status: 'active',
    remark: '一号仓库智能主机'
  },
  {
    hostId: 'HOST-2023-002',
    name: '智能主机002',
    ipAddress: '192.168.1.102',
    status: 'active',
    remark: '二号仓库智能主机'
  },
  {
    hostId: 'HOST-2023-003',
    name: '智能主机003',
    ipAddress: '192.168.1.103',
    status: 'maintenance',
    remark: '三号仓库智能主机（维护中）'
  },
  {
    hostId: 'HOST-2023-004',
    name: '智能主机004',
    ipAddress: '192.168.1.104',
    status: 'inactive',
    remark: '四号仓库智能主机（未使用）'
  },
  {
    hostId: 'HOST-2023-005',
    name: '智能主机005',
    ipAddress: '192.168.1.105',
    status: 'active',
    remark: '五号仓库智能主机'
  }
];

// 重置表并添加测试数据
const resetAndAddTestData = async () => {
  try {
    // 确保表存在
    await SmartHost.sync({
      force: true // 这将删除表（如果存在）并重新创建
    });
    
    console.log('SmartHost表已创建或重置');
    
    // 插入测试数据
    const createdHosts = await SmartHost.bulkCreate(testData.map(item => ({
      host_id: item.hostId,
      name: item.name,
      ip_address: item.ipAddress,
      status: item.status,
      remark: item.remark
    })));
    
    console.log(`已成功添加 ${createdHosts.length} 条智能主机测试数据`);
    
    // 关闭数据库连接
    await sequelize.close();
  } catch (error) {
    console.error('添加测试数据失败:', error);
    process.exit(1);
  }
};

// 执行脚本
resetAndAddTestData();