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

const ClubAccountTransaction = sequelize.define('ClubAccountTransaction', {
  id: {
    type: DataTypes.BIGINT,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false,
  },
  clubId: {
    type: DataTypes.BIGINT,
    allowNull: false,
    field: 'club_id',
  },
  accountId: {
    type: DataTypes.BIGINT,
    allowNull: false,
    field: 'account_id',
  },
  invoiceId: {
    type: DataTypes.BIGINT,
    allowNull: true,
    field: 'invoice_id',
  },
  paymentClaimId: {
    type: DataTypes.BIGINT,
    allowNull: true,
    field: 'payment_claim_id',
  },
  direction: {
    type: DataTypes.ENUM('credit', 'debit'),
    allowNull: false,
    defaultValue: 'credit',
  },
  bookingType: {
    type: DataTypes.ENUM('manual', 'invoice', 'adjustment', 'payment_claim'),
    allowNull: false,
    defaultValue: 'manual',
    field: 'booking_type',
  },
  status: {
    type: DataTypes.ENUM('planned', 'booked', 'cancelled'),
    allowNull: false,
    defaultValue: 'booked',
  },
  bookingDate: {
    type: DataTypes.DATEONLY,
    allowNull: false,
    field: 'booking_date',
  },
  valueDate: {
    type: DataTypes.DATEONLY,
    allowNull: true,
    field: 'value_date',
  },
  amountCents: {
    type: DataTypes.BIGINT,
    allowNull: false,
    field: 'amount_cents',
  },
  currencyCode: {
    type: DataTypes.STRING(3),
    allowNull: false,
    defaultValue: 'EUR',
    field: 'currency_code',
  },
  reference: {
    type: DataTypes.STRING(255),
    allowNull: true,
  },
  notes: {
    type: DataTypes.TEXT,
    allowNull: true,
  },
  createdByUserId: {
    type: DataTypes.BIGINT,
    allowNull: true,
    field: 'created_by_user_id',
  },
}, {
  underscored: true,
  tableName: 'club_account_transactions',
  timestamps: true,
});

export default ClubAccountTransaction;
