import { Injectable } from '@angular/core';
import { WrenchService } from "../services/wrench.service";
import { SessionDataProviderService} from "./session-data-provider.service";

@Injectable({
  providedIn: 'root'
})
export class UserWalletService {

  mainWalletBalance:number = 0;
  mainWalletCurrency:string = '';

  constructor(public wrenchService: WrenchService,
              public sessionDataProviderService: SessionDataProviderService
  ) {
      if ( this.sessionDataProviderService.session!=""){
          this.getWalletData();
      }
  }
    walletDescription:string="";
    walletPresentation(){
        if( this.walletData?.length > 0 ) {
            //this.walletDescription =  this.walletData[0].amount*0.01 + ' ' + this.walletData[0].description;
        }
    }

  rawWallet:any;
  getWallet(){
   // this.rawWallet = this.getWalletData();
    return this.walletData;
  }

  walletResult:any;
  walletData: [];
  usrData: {
    action:number, member_id: number, uid: string, sessionid: string, limit:20, page:1
  };
   async getWalletData(){
    this.walletData = []; // clean the data
    this.usrData = {
        action:11200,
        member_id: this.sessionDataProviderService.member_id,
        uid: this.sessionDataProviderService.member_uid,
        sessionid: this.sessionDataProviderService.session,
        limit:20,
        page:1 };

       this.wrenchService.getUserWallets(this.usrData).subscribe(
        walletResult => {
          this.walletResult = walletResult;
          console.log("WALLET RETURN->", this.walletResult);
          this.walletData = this.walletResult.result_list;
          // debugger;
          console.log("WALLET RETURN DATA->", this.walletData);
        }
    );
  }
}
