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

const MemberOrderHistory = sequelize.define('MemberOrderHistory', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false
  },
  memberOrderId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'member_order_id'
  },
  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
  },
  changedAt: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    field: 'changed_at'
  },
  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_order_history',
  timestamps: true,
  indexes: [
    { fields: ['member_order_id'] },
    { fields: ['member_id'] },
    { fields: ['club_id'] },
    { fields: ['changed_at'] }
  ]
});

export default MemberOrderHistory;
