import {PayInModel} from './pay-in.model';
import {PayInLenderIncomeModel} from '../abstract/pay-in-lender.income.model';


export class PayInAAARowModel extends PayInLenderIncomeModel {
  public Period: Date;
  public LoanNumber: string;
  public Settlement: Date;
  public LoanFacility: number;
  public Balance: number;
  public InTrail: number;



  constructor(payload: Partial<PayInAAARowModel>){
    super('AAA', payload);
    this.Period = new Date(payload.Period);
    this.LoanNumber = payload.LoanNumber || '';
    this.Settlement = new Date(payload.Settlement);
    this.LoanFacility = payload.LoanFacility || 0;
    this.Balance = payload.Balance || -1;
    this.InTrail = payload.InTrail || 0;
  }

  public convertToPayIn(): PayInModel {
    const pi = new PayInModel({});
    pi.Lender = this.AgencyName;
    pi.LoanNumber = this.LoanNumber;
    pi.Amount = this.LoanFacility;
    pi.Settlement = this.Settlement;
    pi.IncomeAmount = this.InTrail;
    pi.IncomeType = 'Trail';
    pi.Balance = this.Balance;
    pi.OffsetBalance = -1;
    pi.Ts = this.Period;
    return pi;
  }

  public isMatch(pi: PayInModel): boolean {
    return  this.LoanNumber === pi.LoanNumber &&  this.LoanNumber !== '' &&
      this.AgencyName === pi.Lender && this.AgencyName !== '' &&
      this.InTrail === pi.IncomeAmount &&
      this.Balance === pi.Balance &&
      'Trail' === pi.IncomeType;
  }
}
