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

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

  constructor(     public sessionDataProviderService: SessionDataProviderService,
                   private wrenchService: WrenchService) {
      console.log("*****  FIRST WaitingInterestService==> --- > ");
      this.getInterestList();
  }

  usrData: {
    action: number, member_id: number, uid: string, sessionid: string, limit: 20, page: 1, offset: 0
  };

  interestTotalData: any;
  interestJobsData: [];
  total_jobs: number = 0;
  interestDate: string;

  getInterestList() {
      console.log("*****  ACTUAL WaitingInterestService==> --- > ");

      this.usrData = {
      action: 13005,
      member_id: this.sessionDataProviderService.member_id,
      uid: this.sessionDataProviderService.member_uid,
      sessionid: this.sessionDataProviderService.session,
      limit: 20, page: 1, offset: 0
    }

    this.wrenchService.getWaitingInterest(this.usrData).subscribe(
        interestTotalData => {
          this.interestTotalData = interestTotalData;
          console.log("interestTotalData  RETURN->", this.interestTotalData);
          this.interestJobsData = this.interestTotalData.result_list;
          this.total_jobs = this.interestJobsData.length;
          console.log("jobManagerJobsData RETURN DATA->", this.interestJobsData);
        }
    );
  }

    interestStatus(JobData, InterestLits:[]){

        if ( InterestLits  == undefined){
            return false;
        }
        for (var i = 0; i < InterestLits.length; i++)
        {
            // console.log("GGGGG1----- ", InterestLits[i]);
            // console.log("GGGGG2----- ", InterestLits[i]["offer_code"]);
            // console.log("GGGGG3----- ",  JobData.offer_code);
            if (InterestLits[i]["offer_code"] === JobData.offer_code)
            {
                this.interestDate =InterestLits[i]["sent"];
                return true;
            }
        }

        return false;
    }
}
