import {UploadMetaModel} from './uploadMetaModel';
import {PayInModel} from './pay-in.model';
import {FunderAaaTrailModel} from './funder.aaa.trail.model';


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

  public AAA?: FunderAaaTrailModel[];

  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.Funder = payload.Funder || '';
    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 => {
        const r = new FunderAaaTrailModel(v);
        this.AAA.push(r);
      });
    }

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

}
