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

const ClubCommunicationDeliveryLog = sequelize.define('ClubCommunicationDeliveryLog', {
  id: {
    type: DataTypes.BIGINT,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false,
  },
  clubId: {
    type: DataTypes.BIGINT,
    allowNull: false,
    field: 'club_id',
  },
  threadId: {
    type: DataTypes.BIGINT,
    allowNull: false,
    field: 'thread_id',
  },
  recipientId: {
    type: DataTypes.BIGINT,
    allowNull: true,
    field: 'recipient_id',
  },
  createdByUserId: {
    type: DataTypes.BIGINT,
    allowNull: true,
    field: 'created_by_user_id',
  },
  status: {
    type: DataTypes.ENUM('sent', 'failed', 'skipped'),
    allowNull: false,
    defaultValue: 'failed',
  },
  attemptNo: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 1,
    field: 'attempt_no',
  },
  retryable: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
  },
  errorCode: {
    type: DataTypes.STRING(64),
    allowNull: true,
    field: 'error_code',
  },
  errorMessage: {
    type: DataTypes.TEXT,
    allowNull: true,
    field: 'error_message',
  },
  transportMessageId: {
    type: DataTypes.STRING(255),
    allowNull: true,
    field: 'transport_message_id',
  },
  transportResponse: {
    type: DataTypes.TEXT,
    allowNull: true,
    field: 'transport_response',
  },
}, {
  underscored: true,
  tableName: 'club_communication_delivery_logs',
  timestamps: true,
});

export default ClubCommunicationDeliveryLog;
