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

const BillingRun = sequelize.define('BillingRun', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false
  },
  clubId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'club_id'
  },
  templateId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'template_id'
  },
  name: {
    type: DataTypes.STRING(255),
    allowNull: false
  },
  periodStart: {
    type: DataTypes.DATEONLY,
    allowNull: false,
    field: 'period_start'
  },
  periodEnd: {
    type: DataTypes.DATEONLY,
    allowNull: false,
    field: 'period_end'
  },
  selfRecipientUserId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'self_recipient_user_id'
  },
  selfRecipientName: {
    type: DataTypes.STRING(255),
    allowNull: false,
    field: 'self_recipient_name'
  },
  hourlyRate: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    field: 'hourly_rate'
  },
  computedHoursTotal: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    defaultValue: 0,
    field: 'computed_hours_total'
  },
  iban: {
    type: DataTypes.STRING(64),
    allowNull: true
  },
  ibanWithoutCountry: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'iban_without_country'
  },
  sessionLabel: {
    type: DataTypes.STRING(255),
    allowNull: true,
    field: 'session_label'
  },
  sameAccountCheckbox: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'same_account_checkbox'
  },
  omitSelfRecipientName: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'omit_self_recipient_name'
  },
  omitIban: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'omit_iban'
  },
  omitLocationText: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'omit_location_text'
  },
  omitDocumentDate: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'omit_document_date'
  },
  omitSessionLabel: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    field: 'omit_session_label'
  },
  locationText: {
    type: DataTypes.STRING(255),
    allowNull: true,
    field: 'location_text'
  },
  documentDate: {
    type: DataTypes.DATEONLY,
    allowNull: true,
    field: 'document_date'
  },
  status: {
    type: DataTypes.ENUM('draft', 'generated', 'finalized', 'cancelled'),
    allowNull: false,
    defaultValue: 'draft'
  },
  createdByUserId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    field: 'created_by_user_id'
  }
}, {
  tableName: 'billing_run',
  underscored: true,
  timestamps: true
});

export default BillingRun;
