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

const ClubCommunicationThread = sequelize.define('ClubCommunicationThread', {
  id: {
    type: DataTypes.BIGINT,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false,
  },
  clubId: {
    type: DataTypes.BIGINT,
    allowNull: false,
    field: 'club_id',
  },
  threadType: {
    type: DataTypes.ENUM('direct', 'group', 'broadcast'),
    allowNull: false,
    defaultValue: 'direct',
    field: 'thread_type',
  },
  subject: {
    type: DataTypes.STRING(255),
    allowNull: false,
  },
  status: {
    type: DataTypes.ENUM('draft', 'scheduled', 'sent', 'archived'),
    allowNull: false,
    defaultValue: 'draft',
  },
  createdByUserId: {
    type: DataTypes.BIGINT,
    allowNull: true,
    field: 'created_by_user_id',
  },
  distributionGroupId: {
    type: DataTypes.BIGINT,
    allowNull: true,
    field: 'distribution_group_id',
  },
  recipientMemberId: {
    type: DataTypes.BIGINT,
    allowNull: true,
    field: 'recipient_member_id',
  },
  scheduledAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'scheduled_at',
  },
  recipientFilters: {
    type: DataTypes.JSON,
    allowNull: true,
    field: 'recipient_filters',
  },
  sentAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'sent_at',
  },
}, {
  underscored: true,
  tableName: 'club_communication_threads',
  timestamps: true,
});

export default ClubCommunicationThread;
