import _ from 'lodash';

import { convertIntoDates } from '../helpers/column-desciptions.helper';
import { ECollaterals } from '../enums/collaterals.enum';

interface IReceivableItemLocal {
  bbcDate: Date;
  invoiceDate: Date;
  invoiceNumber: string;
  customerTitle: string;
  dueDate: Date;
  invoiceAmount: number;
  originalAmount: number;
  invoiceDetail1: string;
  invoiceDetail2: string;
  invoiceDetail3: string;
}

export class ReceivableItem implements IReceivableItemLocal {

  bbcDate: Date = null;
  invoiceDate: Date = null;
  invoiceNumber: string = '';
  customerTitle: string = 'NO CUSTOMER';
  dueDate: Date = null;
  invoiceAmount: number = 0;
  originalAmount: number = 0;
  invoiceDetail1: string = '';
  invoiceDetail2: string = '';
  invoiceDetail3: string = '';

  constructor(item: Partial<ReceivableItem>, bbcDate = null) {
    const itemWithDates = convertIntoDates(item, ECollaterals.RECEIVABLE);
    const itemWithoutNulls = _.omitBy(itemWithDates, (value) => value === null);
    Object.assign(this, itemWithoutNulls);
    this.bbcDate = bbcDate;
  }
}
