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

const ClubAccount = sequelize.define('ClubAccount', {
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id',
  },
  name: {
    type: DataTypes.STRING(160),
    allowNull: false,
  },
  accountHolder: {
    type: DataTypes.STRING(255),
    allowNull: true,
    field: 'account_holder',
  },
  bankName: {
    type: DataTypes.STRING(160),
    allowNull: true,
    field: 'bank_name',
  },
  iban: {
    type: DataTypes.STRING(34),
    allowNull: true,
  },
  bic: {
    type: DataTypes.STRING(11),
    allowNull: true,
  },
  accountType: {
    type: DataTypes.ENUM('bank', 'cash', 'virtual'),
    allowNull: false,
    defaultValue: 'bank',
    field: 'account_type',
  },
  usageType: {
    type: DataTypes.ENUM('general', 'membership_fees', 'donations', 'expenses', 'reserve', 'petty_cash'),
    allowNull: false,
    defaultValue: 'general',
    field: 'usage_type',
  },
  currencyCode: {
    type: DataTypes.STRING(3),
    allowNull: false,
    defaultValue: 'EUR',
    field: 'currency_code',
  },
  allowSepaCollections: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'allow_sepa_collections',
  },
  allowOutgoingPayments: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: true,
    field: 'allow_outgoing_payments',
  },
  isDefault: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'is_default',
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive', 'archived'),
    allowNull: false,
    defaultValue: 'active',
  },
  notes: {
    type: DataTypes.TEXT,
    allowNull: true,
  },
  archivedAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'archived_at',
  },
  sortOrder: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    field: 'sort_order',
  },
}, {
  tableName: 'club_accounts',
  underscored: true,
  timestamps: true,
});

export default ClubAccount;
