import { Injectable } from "@angular/core";
import { KGApiService } from 'src/app/services/base-service/app-api.service';
import { environment } from 'src/environments/environment';
import { Application } from 'src/app/models/application.model';
@Injectable({
  providedIn: "root"
})
export class ApplicationService {
  _application_url: string = environment.app_api_base_url + '/Application';
  
  constructor(private kgapiservice: KGApiService) { }
  getApplications() {
    return this.kgapiservice.loadItems(this._application_url);
  }

  getNewApplications() {
    return this.kgapiservice.loadItems(this._application_url);
  }

  saveApplication(data: any) {
    return this.kgapiservice.saveItems(this._application_url,data);
  }

  getApplication(id: string) {
    return this.kgapiservice.loadItems(this._application_url);
  }

  findApplication(id: string) {
    return this.kgapiservice.loadItem(this._application_url+'/'+id);
  }

  getApplicationsByStatus(status: string): Promise<any> {
    return this.kgapiservice.loadItems(this._application_url + "/status/" + status);
  }

  getApplicationsByType(type: string): Promise<any> {
    return this.kgapiservice.loadItems(this._application_url + "/type/" + type);
  }
  getApplicationsByStatusAndType(status: string,type: string): Promise<any> {
    return this.kgapiservice.loadItems(this._application_url  + "/type/" + type + "/status/" + status);
  }
  createApplication(application:Application){
    return this.kgapiservice.saveItems(this._application_url, application);
  }
  updateApplication(applicationId:string, application:Application){
    return this.kgapiservice.patchItems(this._application_url+"/"+applicationId, application);
  }
  deleteApplication(applicationId:string){
    return this.kgapiservice.deleteItems(this._application_url+"/"+applicationId);
  }
}
