import {PayInModel} from './pay-in.model';


export class PayInAAARowModel {
  private Lender = 'AAA';
  public Period: Date;
  public LoanNumber: string;
  public Settlement: Date;
  public LoanAmount: number;
  public Balance: number;
  public InTrail: number;

  public matchedPayIn?: PayInModel | -1;

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

  public asPayIn(): PayInModel {
    if ( this.matchedPayIn !== undefined && this.matchedPayIn !== -1 ) {
      return this.matchedPayIn;
    }
    const pi = new PayInModel({});
    pi.Lender = this.Lender;
    pi.LoanNumber = this.LoanNumber;
    pi.Amount = this.LoanAmount;
    pi.Settlement = this.Settlement;
    pi.IncomeAmount = this.InTrail;
    pi.IncomeType = 'Trail';
    pi.Ts = this.Period;

    return pi;
  }
}
