import { Injectable } from '@angular/core';
import { Demande } from '../modules/demande';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Constant } from '../helper/constant';
import { SignaturePage } from '../modules/signaturePage';
import { EnvServiceFactory } from './env.service.provider';

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

  apiUrl: string = EnvServiceFactory().apiUrl;
  constant = new Constant();
  
  constructor(private httpClient : HttpClient) { }


  addDemande(demande: Demande){
    var body = JSON.stringify(demande);
    const headers = new HttpHeaders();
    return this.httpClient.post(this.apiUrl+"demande/add", demande, {headers:headers});
   }

   getForUser(id:number){
    return this.httpClient.get(this.apiUrl+"demande/getForUser?id="+id);
   }

   getAllForUser(id:number, page : number, limit : number, statut : string, eDemande : string, date : string){
    return this.httpClient.get(this.apiUrl+"demande/getForUser/search?id="+id+"&page="+page+"&limit="+limit+"&statut="+statut+"&eDemande="+eDemande+"&date="+date);
   }


   modifyPdfToken(data : SignaturePage[], token: string){
    return this.httpClient.post(this.apiUrl+"upload/modifyPdf/"+token, data);
   }

   getDemandeToken(token : string){
    return this.httpClient.get(this.apiUrl+"token/getToken?token="+token);
   }

   relaunchDemand(idDemand : number, idDestinataire : number){
    return this.httpClient.get(this.apiUrl+"demande/relaunch?idDemand="+idDemand+"&idDestinataire="+idDestinataire);
   }

   cancelDemand(idDemand : number){
    return this.httpClient.get(this.apiUrl+"demande/canceled?idDemand="+idDemand);
   }


}
