import { DataTypes } from 'sequelize';
import sequelize from '../database.js';

const ClubDocument = sequelize.define('ClubDocument', {
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id',
  },
  documentType: {
    type: DataTypes.STRING(32),
    allowNull: false,
    field: 'document_type',
  },
  title: {
    type: DataTypes.STRING(255),
    allowNull: false,
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
  },
  status: {
    type: DataTypes.STRING(32),
    allowNull: false,
    defaultValue: 'active',
  },
  visibilityScope: {
    type: DataTypes.STRING(32),
    allowNull: false,
    defaultValue: 'board',
    field: 'visibility_scope',
  },
  ownerUserId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'owner_user_id',
  },
  currentVersionNo: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 1,
    field: 'current_version_no',
  },
  archivedAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'archived_at',
  },
}, {
  tableName: 'club_documents',
  underscored: true,
  timestamps: true,
  indexes: [
    { fields: ['club_id', 'document_type', 'status'] },
    { fields: ['club_id', 'visibility_scope'] },
    { fields: ['club_id', 'current_version_no'] },
  ],
});

export default ClubDocument;
