import {UploadMetaModel} from './uploadMetaModel';
import {PayInModel} from './pay-in.model';
import {PayInAAARowModel} from './Pay.In.AAA.Row.model';
import {PayInConnectiveModel} from './pay-in-connective.model';
import {PayInResimacXlsModel} from './pay-in-resimac-xls.mode';
import {PayInResimacPdfModel} from './pay-in-resimac-pdf.model';
import {PayInPepperModel} from './pay-in-pepper.model';



export class UploadAnalysisModel {
  public Id: number;
  public Lender: string;
  public Mime: string;
  public PayIn: PayInModel[];

  public AAA?: PayInAAARowModel[];
  public Connective?: PayInConnectiveModel[];
  public ResimacXls?: PayInResimacXlsModel[];
  public ResimacPdf?: PayInResimacPdfModel[];
  public Pepper?: PayInPepperModel[];

  public IsDuplicate: boolean;
  public Uid?: string;  // client side unique id when upload
  public Input?: UploadMetaModel;

  constructor(payload: Partial<UploadAnalysisModel>){
    this.Id = payload.Id || 0 ;
    this.Lender = payload.Lender || '';
    this.Mime = payload.Mime || '';
    if ( payload.PayIn && payload.PayIn.length > 0 ) {
      this.PayIn = [];
    }else{
      this.PayIn = [];
      if ( payload.PayIn ) {
        payload.PayIn.forEach(
          v => {
            const pi = new PayInModel(v);
            this.PayIn.push(pi);
          }
        );
      }
    }

    this.AAA = [];
    if ( payload.AAA ) {
      payload.AAA.forEach( v => { this.AAA.push(new PayInAAARowModel(v)); });
    }

    this.Connective = [];
    if ( Array.isArray(payload.Connective) ) {
      payload.Connective.forEach( v => { this.Connective.push(new PayInConnectiveModel(v)); });
    }
    this.ResimacXls = [];
    if ( Array.isArray(payload.ResimacXls) ) {
      payload.ResimacXls.forEach( v => { this.ResimacXls.push(new PayInResimacXlsModel(v)); });
    }
    this.ResimacPdf = [];
    if (Array.isArray(payload.ResimacPdf)){
      payload.ResimacPdf.forEach( v => { this.ResimacPdf.push(new PayInResimacPdfModel(v)); });
    }
    this.Pepper = [];
    if (Array.isArray(payload.Pepper)){
      payload.Pepper.forEach(v => { this.Pepper.push (new PayInPepperModel(v)); });
    }

    this.IsDuplicate = payload.IsDuplicate || false;
    this.Uid = payload.Uid || '' ;
    this.Input = new UploadMetaModel(payload.Input || {});
  }

}
