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

const CattleAcademy = sequelize.define('CattleAcademy', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  title: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: '标题'
  },
  coverImage: {
    type: DataTypes.STRING(500),
    allowNull: true,
    comment: '封面图URL'
  },
  content: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '内容'
  },
  summary: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '摘要'
  },
  category: {
    type: DataTypes.STRING(100),
    allowNull: true,
    comment: '分类'
  },
  tags: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: '标签'
  },
  sort: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '排序'
  },
  status: {
    type: DataTypes.BOOLEAN,
    defaultValue: true,
    comment: '状态'
  },
  viewCount: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '浏览次数'
  },
  author: {
    type: DataTypes.STRING(100),
    allowNull: true,
    comment: '作者'
  },
  publishTime: {
    type: DataTypes.DATE,
    allowNull: true,
    comment: '发布时间'
  },
  isTop: {
    type: DataTypes.BOOLEAN,
    defaultValue: false,
    comment: '是否置顶'
  },
  isRecommend: {
    type: DataTypes.BOOLEAN,
    defaultValue: false,
    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: 'cattle_academy',
  timestamps: true,
  createdAt: 'createdAt',
  updatedAt: 'updatedAt',
  paranoid: false
});

module.exports = CattleAcademy;
