import _ from 'lodash';

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

interface IPayableAccountLocal {
  bbcDate: Date;
  apDate: string;
  poNumber: string;
  customerName: string;
  amount: number;
  otherInformation1: string;
  otherInformation2: string;
  otherInformation3: string;
}

export class PayableAccountItem implements IPayableAccountLocal {

  bbcDate: Date = null;
  apDate: string = '';
  poNumber: string = '';
  customerName: string = '';
  amount: number = 0;
  otherInformation1: string = '';
  otherInformation2: string = '';
  otherInformation3: string = '';

  constructor(item: Partial<PayableAccountItem>, bbcDate = null) {
    const itemWithDates = convertIntoDates(item, ECollaterals.ACCOUNT_PAYABLE);
    const itemWithoutNulls = _.omitBy(itemWithDates, (value) => value === null);
    Object.assign(this, itemWithoutNulls);
    this.bbcDate = bbcDate;
    this.apDate = !this.apDate ? (new Date()).toISOString() : this.apDate;
  }
}
