import { DataTypes, Model, Optional } from 'sequelize';
import { sequelize } from '@config/database';

export interface From16SapReadFileAttributes {
  id: number;
  fileName: string;
  totalRecords: number;
  totalCreditNotes: number;
  totalDebitNotes: number;
  createdAt: Date;
  updatedAt: Date;
}

interface From16SapReadFileCreationAttributes
  extends Optional<From16SapReadFileAttributes, 'id' | 'createdAt' | 'updatedAt'> {}

class From16SapReadFile
  extends Model<From16SapReadFileAttributes, From16SapReadFileCreationAttributes>
  implements From16SapReadFileAttributes
{
  public id!: number;
  public fileName!: string;
  public totalRecords!: number;
  public totalCreditNotes!: number;
  public totalDebitNotes!: number;
  public createdAt!: Date;
  public updatedAt!: Date;
}

From16SapReadFile.init(
  {
    id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true },
    fileName: { type: DataTypes.STRING(255), allowNull: false, unique: true, field: 'file_name' },
    totalRecords: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, field: 'total_records' },
    totalCreditNotes: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, field: 'total_credit_notes' },
    totalDebitNotes: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, field: 'total_debit_notes' },
    createdAt: { type: DataTypes.DATE, allowNull: false, field: 'created_at' },
    updatedAt: { type: DataTypes.DATE, allowNull: false, field: 'updated_at' },
  },
  {
    sequelize,
    tableName: 'from16_sap_read_file',
    timestamps: true,
    underscored: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
  }
);

export { From16SapReadFile };
