import { Injectable } from '@angular/core';
import { Observable } from "rxjs";
import { HttpClient, HttpHeaders, HttpParams, } from "@angular/common/http";
import { ApiRequestService } from "src/app/services/api/api-request.service";
import { environment } from 'src/environments/environment';
@Injectable({
  providedIn: 'root'
})
export class Data_lakeservice{
  private baseURL = "Data_lake/Data_lake" ;  constructor(
    private http: HttpClient,
    private apiRequest: ApiRequestService,
  ) { }
  getAll(page?: number, size?: number): Observable<any> {
    return this.apiRequest.get(this.baseURL);
  }
  getById(id: number): Observable<any> {
    const _http = this.baseURL + "/" + id;
    return this.apiRequest.get(_http);
  }
  create(data: any): Observable<any> {
    return this.apiRequest.post(this.baseURL, data);
  }
  update(id: number, data: any): Observable<any> {
    const _http = this.baseURL + "/" + id;
    return this.apiRequest.put(_http, data);
  }
  delete(id: number): Observable<any> {
    const _http = this.baseURL + "/" + id;
    return this.apiRequest.delete(_http);
  }
  
  // New method for updating JSON
  updateJson(id: number): Observable<any> {
    const _http = this.baseURL + "/json/" + id;
    return this.apiRequest.put(_http, {});
  }
  
  // Method to fetch available keys from API
  fetchAvailableKeys(url: string, sureId: number): Observable<string[]> {
    const apiUrl = `chart/getAllKeys?apiUrl=${encodeURIComponent(url)}&sureId=${sureId}`;
    return this.apiRequest.get(apiUrl);
  }

  // Method to fetch blending keys for a specific lake ID
  fetchBlendingKeys(lakeId: number): Observable<any> {
    const _http = `${this.baseURL}/keys/${lakeId}`;
    return this.apiRequest.get(_http);
  }
  
  // Method to update calculated fields for a data lake item
  updateCalculatedFields(id: number, calculatedFieldJson: string, isCalculatedField: boolean): Observable<any> {
    const _http = this.baseURL + "/" + id;
    const data = {
      calculated_field_json: calculatedFieldJson,
      iscalculatedfield: isCalculatedField
    };
    return this.apiRequest.put(_http, data);
  }
  
  // Method to enable webhook for a data lake item
  enableWebhook(id: number): Observable<any> {
    const _http = `${this.baseURL}/webhook/${id}`;
    return this.apiRequest.get(_http);
  }
// updateaction
}