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

const ClubDocumentVersion = sequelize.define('ClubDocumentVersion', {
  documentId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'document_id',
  },
  versionNo: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'version_no',
  },
  fileName: {
    type: DataTypes.STRING(255),
    allowNull: false,
    field: 'file_name',
  },
  storagePath: {
    type: DataTypes.STRING(500),
    allowNull: false,
    field: 'storage_path',
  },
  mimeType: {
    type: DataTypes.STRING(120),
    allowNull: true,
    field: 'mime_type',
  },
  fileSizeBytes: {
    type: DataTypes.BIGINT,
    allowNull: true,
    field: 'file_size_bytes',
  },
  checksumSha256: {
    type: DataTypes.STRING(64),
    allowNull: true,
    field: 'checksum_sha256',
  },
  uploadedByUserId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'uploaded_by_user_id',
  },
  uploadedAt: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    field: 'uploaded_at',
  },
  changeNote: {
    type: DataTypes.TEXT,
    allowNull: true,
    field: 'change_note',
  },
}, {
  tableName: 'club_document_versions',
  underscored: true,
  timestamps: false,
  indexes: [
    { unique: true, fields: ['document_id', 'version_no'] },
  ],
});

export default ClubDocumentVersion;
