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

const ProductionMaterialCertification = sequelize.define('ProductionMaterialCertification', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  materialName: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: '生产资料名称'
  },
  materialType: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '生产资料类型'
  },
  manufacturer: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: '生产厂商'
  },
  certificationNumber: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '认证编号'
  },
  certificationType: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '认证类型'
  },
  certificationAuthority: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: '认证机构'
  },
  issueDate: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: '发证日期'
  },
  expiryDate: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: '有效期至'
  },
  certificationStatus: {
    type: DataTypes.ENUM('valid', 'expired', 'suspended', 'revoked'),
    defaultValue: 'valid',
    comment: '认证状态'
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '产品描述'
  },
  specifications: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '技术规格'
  },
  applicableScope: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '适用范围'
  },
  contactPerson: {
    type: DataTypes.STRING(100),
    allowNull: true,
    comment: '联系人'
  },
  contactPhone: {
    type: DataTypes.STRING(20),
    allowNull: true,
    comment: '联系电话'
  },
  remarks: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '备注'
  },
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    comment: '创建时间'
  },
  updatedAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    comment: '更新时间'
  }
}, {
  tableName: 'production_material_certifications',
  timestamps: true,
  createdAt: 'createdAt',
  updatedAt: 'updatedAt',
  paranoid: false
});

module.exports = ProductionMaterialCertification;
