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

const ApprovalProcess = sequelize.define('ApprovalProcess', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  title: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: '审批标题'
  },
  type: {
    type: DataTypes.ENUM('enterprise', 'license', 'project', 'other'),
    allowNull: false,
    comment: '审批类型'
  },
  applicant: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '申请人'
  },
  phone: {
    type: DataTypes.STRING(20),
    allowNull: true,
    comment: '联系电话'
  },
  farmName: {
    type: DataTypes.STRING(255),
    allowNull: true,
    comment: '养殖场名称'
  },
  quantity: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: '认证数量'
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '审批说明'
  },
  status: {
    type: DataTypes.ENUM('pending', 'approved', 'rejected', 'processing'),
    defaultValue: 'pending',
    comment: '审批状态'
  },
  approvalComment: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '审批意见'
  },
  approver: {
    type: DataTypes.STRING(100),
    allowNull: true,
    comment: '审批人'
  },
  approvalTime: {
    type: DataTypes.DATE,
    allowNull: true,
    comment: '审批时间'
  },
  files: {
    type: DataTypes.JSON,
    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: 'approval_processes',
  timestamps: true,
  createdAt: 'createdAt',
  updatedAt: 'updatedAt',
  paranoid: false
});

module.exports = ApprovalProcess;
