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

export class ClaimCreditNoteItem extends Model {
  public itemId!: string;
  public creditNoteId!: string;
  public slNo!: number;
  public transactionNo!: string | null;
  public description!: string | null;
  public hsnCd!: string | null;
  public amount!: number;
  public claimAmount!: number | null;
  public tdsAmount!: number | null;
  public creditAmount!: number | null;
  public readonly createdAt!: Date;
  public readonly updatedAt!: Date;
}

ClaimCreditNoteItem.init(
  {
    itemId: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true,
      field: 'item_id',
    },
    creditNoteId: {
      type: DataTypes.UUID,
      allowNull: false,
      field: 'credit_note_id',
    },
    slNo: {
      type: DataTypes.INTEGER,
      allowNull: false,
      field: 'sl_no',
    },
    transactionNo: {
      type: DataTypes.STRING(100),
      allowNull: true,
      field: 'transaction_no',
    },
    description: {
      type: DataTypes.TEXT,
      allowNull: true,
      field: 'description',
    },
    hsnCd: {
      type: DataTypes.STRING(20),
      allowNull: true,
      field: 'hsn_cd',
    },
    amount: {
      type: DataTypes.DECIMAL(15, 2),
      allowNull: false,
      defaultValue: 0,
      field: 'amount',
    },
    claimAmount: {
      type: DataTypes.DECIMAL(15, 2),
      allowNull: true,
      defaultValue: 0,
      field: 'claim_amount',
    },
    tdsAmount: {
      type: DataTypes.DECIMAL(15, 2),
      allowNull: true,
      defaultValue: 0,
      field: 'tds_amount',
    },
    creditAmount: {
      type: DataTypes.DECIMAL(15, 2),
      allowNull: true,
      defaultValue: 0,
      field: 'credit_amount',
    },
  },
  {
    sequelize,
    tableName: 'claim_credit_note_items',
    underscored: true,
    timestamps: true,
  }
);
