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

const Club = sequelize.define('Club', {
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true,
  },
  greetingText: {
    type: DataTypes.TEXT,
    allowNull: true,
    field: 'greeting_text'
  },
  associationMemberNumber: {
    type: DataTypes.STRING,
    allowNull: true,
    field: 'association_member_number'
  },
  myTischtennisFedNickname: {
    type: DataTypes.STRING,
    allowNull: true,
    field: 'my_tischtennis_fed_nickname',
    comment: 'Federation short name for rankings (e.g. HeTTV)'
  },
  autoFetchRankings: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'auto_fetch_rankings',
    comment: 'Enable automatic TTR/QTTR rankings fetch for this club'
  },
  countryCode: {
    type: DataTypes.STRING(2),
    allowNull: false,
    defaultValue: 'DE',
    field: 'country_code',
    comment: 'ISO 3166-1 alpha-2 country code for regional calendar data'
  },
  stateCode: {
    type: DataTypes.STRING(16),
    allowNull: true,
    field: 'state_code',
    comment: 'ISO 3166-2 subdivision code for regional calendar data, e.g. DE-NW'
  },
  memberDataQualityRequirements: {
    type: DataTypes.JSON,
    allowNull: true,
    field: 'member_data_quality_requirements',
    comment: 'Configures which member fields are required for data quality checks'
  },
  feeRules: {
    type: DataTypes.JSON,
    allowNull: true,
    field: 'fee_rules',
    comment: 'Manual contribution rules for common club member groups'
  },
  outgoingInvoicePrefix: {
    type: DataTypes.STRING(24),
    allowNull: false,
    defaultValue: 'RE',
    field: 'outgoing_invoice_prefix'
  },
  outgoingInvoiceNextNumber: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 1,
    field: 'outgoing_invoice_next_number'
  },
  incomingInvoicePrefix: {
    type: DataTypes.STRING(24),
    allowNull: false,
    defaultValue: 'EI',
    field: 'incoming_invoice_prefix'
  },
  incomingInvoiceNextNumber: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 1,
    field: 'incoming_invoice_next_number'
  }
}, {
  tableName: 'clubs',
  underscored: true,
  timestamps: true
});

export default Club;
