import { Injectable } from '@angular/core';
import { DynaDataService } from '@xdf/gallery';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class AgentService extends DynaDataService {

  serviceURL = './service/agent';

  filedata:any;

  private deletedfiles: any[]=[];
  constructor(private httpClient: HttpClient) {
    super(httpClient);
  }
  getDataForWizard(agentId: number) {
    let params = {};

    if (agentId) {
      params = {
        id: agentId
      };
    }
    return this.httpClient.get(this.serviceURL + '/connection/data', {
      params
    });
  }

  getCountryDataForWizard() {
    return this.httpClient.get(this.serviceURL + '/countries');
  }

  getAgentInfo(AgentId) {
    return this.httpClient.get(this.serviceURL + '/'+AgentId);
  }

  upload(formData) {
    return this.httpClient.post<any>(this.serviceURL + '/file-upload', formData, {
      reportProgress: true,
      observe: 'events'
    });
  }

  getChannelDatForWizard() {
    return this.httpClient.get(this.serviceURL + '/channels');
  }

  synchronize(id: number, user: string) {
    return this.httpClient.get(this.serviceURL + '/synchronize/' + id, {
      params: {
        user
      }
    });
  }

  loadfileData(data:any){
    this.filedata=[];
    this.filedata.push(data);
  }

  getfileData(){
    return this.filedata;
  }

  addDeletedFile(data:any){
    this.deletedfiles.push(data);
  }

  getDeletedFiles():any[]{
    return this.deletedfiles
  }

  spliceDeletedFile(){
    return this.deletedfiles.splice(0,1);
  }

  emptyDeletedFiles(){
    this.deletedfiles=[];
  }

  retryData(uuid:string){
    return this.httpClient.put<any>(this.serviceURL+'/file-upload/'+uuid,uuid)
  }

  deleteFile(uuid:string){
    return this.httpClient.delete<any>(this.serviceURL+'/file-upload/'+uuid)
  }

}
