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

const MemberOrder = sequelize.define('MemberOrder', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false
  },
  memberId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'member_id'
  },
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id'
  },
  item: {
    type: DataTypes.STRING,
    allowNull: false
  },
  status: {
    type: DataTypes.ENUM('requested', 'ordered', 'arrived', 'handed_over'),
    allowNull: false,
    defaultValue: 'requested'
  },
  orderDate: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    field: 'order_date'
  },
  statusDate: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    field: 'status_date'
  },
  cost: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    defaultValue: 0
  },
  paidAmount: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    defaultValue: 0,
    field: 'paid_amount'
  },
  budget: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    defaultValue: 0
  },
  paidConfirmed: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'paid_confirmed'
  }
}, {
  underscored: true,
  tableName: 'member_orders',
  timestamps: true,
  indexes: [
    { fields: ['member_id'] },
    { fields: ['club_id'] },
    { fields: ['status'] }
  ]
});

export default MemberOrder;
