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

const ClubPaymentClaim = sequelize.define('ClubPaymentClaim', {
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id'
  },
  memberId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'member_id'
  },
  feeRuleId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'fee_rule_id'
  },
  claimType: {
    type: DataTypes.STRING(32),
    allowNull: false,
    defaultValue: 'membership_fee',
    field: 'claim_type'
  },
  status: {
    type: DataTypes.ENUM('open', 'partially_paid', 'paid', 'written_off', 'cancelled'),
    allowNull: false,
    defaultValue: 'open'
  },
  dueOn: {
    type: DataTypes.DATEONLY,
    allowNull: false,
    field: 'due_on'
  },
  amountCents: {
    type: DataTypes.BIGINT,
    allowNull: false,
    field: 'amount_cents'
  },
  paidAmountCents: {
    type: DataTypes.BIGINT,
    allowNull: false,
    defaultValue: 0,
    field: 'paid_amount_cents'
  },
  currencyCode: {
    type: DataTypes.STRING(3),
    allowNull: false,
    defaultValue: 'EUR',
    field: 'currency_code'
  },
  reminderLevel: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    field: 'reminder_level'
  },
  lastReminderAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'last_reminder_at'
  },
  notes: {
    type: DataTypes.TEXT,
    allowNull: true
  },
  settledAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'settled_at'
  },
  lastPaidAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'last_paid_at'
  },
  archivedAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'archived_at'
  }
}, {
  tableName: 'club_payment_claims',
  underscored: true,
  timestamps: true
});

export default ClubPaymentClaim;
