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

const ClubInvoiceItem = sequelize.define('ClubInvoiceItem', {
  invoiceId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'invoice_id',
  },
  lineNo: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 1,
    field: 'line_no',
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: false,
  },
  quantity: {
    type: DataTypes.DECIMAL(12, 2),
    allowNull: false,
    defaultValue: 1,
  },
  unitPriceCents: {
    type: DataTypes.BIGINT,
    allowNull: false,
    defaultValue: 0,
    field: 'unit_price_cents',
  },
  taxRate: {
    type: DataTypes.DECIMAL(5, 2),
    allowNull: false,
    defaultValue: 0,
    field: 'tax_rate',
  },
  totalCents: {
    type: DataTypes.BIGINT,
    allowNull: false,
    defaultValue: 0,
    field: 'total_cents',
  },
}, {
  tableName: 'club_invoice_items',
  underscored: true,
  timestamps: true,
});

export default ClubInvoiceItem;
