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

const ClubRequest = sequelize.define('ClubRequest', {
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id'
  },
  requestType: {
    type: DataTypes.ENUM('contact', 'trial_training', 'membership', 'sponsoring'),
    allowNull: false,
    defaultValue: 'contact',
    field: 'request_type'
  },
  status: {
    type: DataTypes.ENUM('open', 'in_progress', 'waiting', 'converted', 'rejected', 'archived'),
    allowNull: false,
    defaultValue: 'open'
  },
  workflowStage: {
    type: DataTypes.STRING(64),
    allowNull: true,
    field: 'workflow_stage'
  },
  priority: {
    type: DataTypes.ENUM('low', 'normal', 'high', 'urgent'),
    allowNull: false,
    defaultValue: 'normal'
  },
  subject: {
    type: DataTypes.STRING,
    allowNull: true
  },
  firstName: {
    type: DataTypes.STRING,
    allowNull: true,
    field: 'first_name'
  },
  lastName: {
    type: DataTypes.STRING,
    allowNull: true,
    field: 'last_name'
  },
  email: {
    type: DataTypes.STRING,
    allowNull: true
  },
  phone: {
    type: DataTypes.STRING,
    allowNull: true
  },
  message: {
    type: DataTypes.TEXT,
    allowNull: true
  },
  sourceSystem: {
    type: DataTypes.STRING,
    allowNull: true,
    field: 'source_system'
  },
  receivedAt: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    field: 'received_at'
  },
  assignedUserId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'assigned_user_id'
  },
  assignedMemberId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'assigned_member_id'
  },
  convertedMemberId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'converted_member_id'
  },
  closedAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'closed_at'
  }
}, {
  tableName: 'club_requests',
  underscored: true,
  timestamps: true
});

export default ClubRequest;
