import {LoanModel} from './loan.model';
import {PayOutModel} from './payout.ex.model';
import {PeopleModel} from './people.model';
import {UserExModel} from './userExModel';

export class RewardExModel {
  public Id: number;
  public Ts: Date;
  public ToId: string;
  public Amount: number;
  public Description: string;
  public LoanId: string;
  public FromId: string;
  public PayOutId: number;

  public To?: UserExModel;
  public Loan?: LoanModel;
  public From?: UserExModel;
  public PayOut?: PayOutModel;

  constructor(payload: Partial<RewardExModel>) {
    this.Id = payload.Id || 0;
    if ( payload.Ts ) {
      this.Ts = new Date(payload.Ts);
    }else{
      this.Ts = new Date('1800-01-01');
    }
    this.ToId = payload.ToId || '';
    this.Amount = payload.Amount || 0;
    this.Description = payload.Description || '';
    this.LoanId = payload.LoanId || '';
    this.FromId = payload.FromId || '';
    this.PayOutId = payload.PayOutId || 0;

    if (payload.To) {
      this.To = new UserExModel(payload.To);
    }

    if (payload.Loan) {
      this.Loan = new LoanModel(payload.Loan);
    }

    if ( payload.From) {
      this.From = new UserExModel(payload.From);
    }

    if ( payload. PayOut ) {
      this.PayOut = new PayOutModel(payload.PayOut);
    }

  }
}
