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

/**
 * 设备模型
 * 用于管理保险相关的设备信息
 */
const Device = sequelize.define('Device', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    comment: '设备ID'
  },
  device_number: {
    type: DataTypes.STRING(50),
    allowNull: false,
    unique: true,
    comment: '设备编号'
  },
  device_name: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '设备名称'
  },
  device_type: {
    type: DataTypes.STRING(50),
    allowNull: false,
    comment: '设备类型'
  },
  device_model: {
    type: DataTypes.STRING(100),
    comment: '设备型号'
  },
  manufacturer: {
    type: DataTypes.STRING(100),
    comment: '制造商'
  },
  installation_location: {
    type: DataTypes.STRING(200),
    comment: '安装位置'
  },
  installation_date: {
    type: DataTypes.DATE,
    comment: '安装日期'
  },
  status: {
    type: DataTypes.ENUM('normal', 'warning', 'error', 'offline'),
    defaultValue: 'normal',
    comment: '设备状态：normal-正常，warning-警告，error-故障，offline-离线'
  },
  farm_id: {
    type: DataTypes.INTEGER,
    comment: '所属养殖场ID'
  },
  barn_id: {
    type: DataTypes.INTEGER,
    comment: '所属栏舍ID'
  },
  created_by: {
    type: DataTypes.INTEGER,
    comment: '创建人ID'
  },
  updated_by: {
    type: DataTypes.INTEGER,
    comment: '更新人ID'
  },
  created_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    comment: '创建时间'
  },
  updated_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    comment: '更新时间'
  }
}, {
  tableName: 'devices',
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  comment: '设备信息表'
});

module.exports = Device;

