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

const ClubInvoice = sequelize.define('ClubInvoice', {
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id',
  },
  invoiceDirection: {
    type: DataTypes.STRING(16),
    allowNull: false,
    field: 'invoice_direction',
  },
  invoiceType: {
    type: DataTypes.STRING(32),
    allowNull: false,
    field: 'invoice_type',
  },
  status: {
    type: DataTypes.STRING(32),
    allowNull: false,
    defaultValue: 'draft',
  },
  invoiceNumber: {
    type: DataTypes.STRING(64),
    allowNull: true,
    field: 'invoice_number',
  },
  externalReference: {
    type: DataTypes.STRING(255),
    allowNull: true,
    field: 'external_reference',
  },
  partyId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'party_id',
  },
  accountId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'account_id',
  },
  issuedOn: {
    type: DataTypes.DATEONLY,
    allowNull: true,
    field: 'issued_on',
  },
  dueOn: {
    type: DataTypes.DATEONLY,
    allowNull: true,
    field: 'due_on',
  },
  paidOn: {
    type: DataTypes.DATEONLY,
    allowNull: true,
    field: 'paid_on',
  },
  netAmountCents: {
    type: DataTypes.BIGINT,
    allowNull: false,
    defaultValue: 0,
    field: 'net_amount_cents',
  },
  taxAmountCents: {
    type: DataTypes.BIGINT,
    allowNull: false,
    defaultValue: 0,
    field: 'tax_amount_cents',
  },
  grossAmountCents: {
    type: DataTypes.BIGINT,
    allowNull: false,
    defaultValue: 0,
    field: 'gross_amount_cents',
  },
  currencyCode: {
    type: DataTypes.STRING(3),
    allowNull: false,
    defaultValue: 'EUR',
    field: 'currency_code',
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
  },
  documentId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'document_id',
  },
  createdByUserId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'created_by_user_id',
  },
  archivedAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'archived_at',
  },
}, {
  tableName: 'club_invoices',
  underscored: true,
  timestamps: true,
});

export default ClubInvoice;
