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

const ClubSepaMandate = sequelize.define('ClubSepaMandate', {
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id'
  },
  memberId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'member_id'
  },
  debtorName: {
    type: DataTypes.STRING,
    allowNull: false,
    field: 'debtor_name'
  },
  iban: {
    type: DataTypes.STRING(34),
    allowNull: false
  },
  bic: {
    type: DataTypes.STRING(11),
    allowNull: true
  },
  mandateReference: {
    type: DataTypes.STRING(80),
    allowNull: false,
    field: 'mandate_reference'
  },
  signedOn: {
    type: DataTypes.DATEONLY,
    allowNull: true,
    field: 'signed_on'
  },
  validFrom: {
    type: DataTypes.DATEONLY,
    allowNull: true,
    field: 'valid_from'
  },
  revokedAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'revoked_at'
  },
  status: {
    type: DataTypes.STRING(32),
    allowNull: false,
    defaultValue: 'active'
  },
  historyNote: {
    type: DataTypes.TEXT,
    allowNull: true,
    field: 'history_note'
  }
}, {
  tableName: 'club_sepa_mandates',
  underscored: true,
  timestamps: true
});

export default ClubSepaMandate;
