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

const ClubInvoiceParty = sequelize.define('ClubInvoiceParty', {
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id',
  },
  partyType: {
    type: DataTypes.STRING(32),
    allowNull: false,
    defaultValue: 'customer',
    field: 'party_type',
  },
  status: {
    type: DataTypes.STRING(32),
    allowNull: false,
    defaultValue: 'active',
  },
  name: {
    type: DataTypes.STRING(255),
    allowNull: false,
  },
  contractReference: {
    type: DataTypes.STRING(120),
    allowNull: true,
    field: 'contract_reference',
  },
  validFrom: {
    type: DataTypes.DATEONLY,
    allowNull: true,
    field: 'valid_from',
  },
  validTo: {
    type: DataTypes.DATEONLY,
    allowNull: true,
    field: 'valid_to',
  },
  contactName: {
    type: DataTypes.STRING(255),
    allowNull: true,
    field: 'contact_name',
  },
  email: {
    type: DataTypes.STRING(255),
    allowNull: true,
  },
  phone: {
    type: DataTypes.STRING(80),
    allowNull: true,
  },
  street: {
    type: DataTypes.STRING(255),
    allowNull: true,
  },
  postalCode: {
    type: DataTypes.STRING(24),
    allowNull: true,
    field: 'postal_code',
  },
  city: {
    type: DataTypes.STRING(120),
    allowNull: true,
  },
  countryCode: {
    type: DataTypes.STRING(2),
    allowNull: true,
    defaultValue: 'DE',
    field: 'country_code',
  },
  iban: {
    type: DataTypes.STRING(34),
    allowNull: true,
  },
  bic: {
    type: DataTypes.STRING(11),
    allowNull: true,
  },
  taxIdentifier: {
    type: DataTypes.STRING(64),
    allowNull: true,
    field: 'tax_identifier',
  },
  notes: {
    type: DataTypes.TEXT,
    allowNull: true,
  },
}, {
  tableName: 'club_invoice_parties',
  underscored: true,
  timestamps: true,
  indexes: [
    { fields: ['club_id', 'party_type'] },
    { fields: ['club_id', 'status'] },
    { fields: ['club_id', 'valid_from'] },
    { fields: ['club_id', 'valid_to'] },
  ],
});

export default ClubInvoiceParty;
