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

const ClubTask = sequelize.define('ClubTask', {
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id'
  },
  title: {
    type: DataTypes.STRING(255),
    allowNull: false
  },
  taskType: {
    type: DataTypes.STRING(64),
    allowNull: true,
    field: 'task_type'
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true
  },
  status: {
    type: DataTypes.ENUM('open', 'in_progress', 'waiting', 'done', 'cancelled', 'archived'),
    allowNull: false,
    defaultValue: 'open'
  },
  priority: {
    type: DataTypes.ENUM('low', 'normal', 'high', 'urgent'),
    allowNull: false,
    defaultValue: 'normal'
  },
  dueAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'due_at'
  },
  remindAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'remind_at'
  },
  createdByUserId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'created_by_user_id'
  },
  assignedUserId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'assigned_user_id'
  },
  automationSource: {
    type: DataTypes.STRING(64),
    allowNull: true,
    field: 'automation_source'
  },
  automationKey: {
    type: DataTypes.STRING(255),
    allowNull: true,
    field: 'automation_key'
  },
  relatedEntityType: {
    type: DataTypes.STRING(32),
    allowNull: true,
    field: 'related_entity_type'
  },
  relatedEntityId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'related_entity_id'
  },
  completedAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'completed_at'
  },
  archivedAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'archived_at'
  },
  sourceSnapshot: {
    type: DataTypes.JSON,
    allowNull: true,
    field: 'source_snapshot'
  }
}, {
  tableName: 'club_tasks',
  underscored: true,
  timestamps: true
});

export default ClubTask;
