// Questo file fa parte di MyTown.
// MyTown è software libero: puoi ridistribuirlo e/o modificarlo secondo
// i termini della GNU Affero General Public License come pubblicata dalla
// Free Software Foundation, versione 3.
// Distribuito senza ALCUNA GARANZIA; vedi la GNU AGPL v3 per i dettagli.
// Copyright (C) Kondor Consulting & Services S.r.l.
// SPDX-License-Identifier: AGPL-3.0-or-later

import { Injectable } from '@angular/core';
import { MonoTypeOperatorFunction, finalize, Observable, of, OperatorFunction, Subject} from 'rxjs'; // necessario per leggere e contenere 
import { catchError, map, tap, switchMap } from 'rxjs/operators'; // permette di rintracciare errori 
import { HttpClient } from '@angular/common/http';

import { ConfigService } from './config.service';

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

   constructor(private config: ConfigService,
              private http: HttpClient) {}

  getListLocations(pl: any): Observable<any> { // la lista prende anche byId se metto bk.bk_id = num
    return this.http.post(`${this.config.bakekaUrl}places/getListPlaces`, pl, {  observe: "response" }).pipe(
    map(response => response.body),

  ); }

  getPlace(cmp_id: number, plc_id: number): Observable<any>{
    return this.http.get(`${this.config.bakekaUrl}places/getPlace/${cmp_id}/${plc_id}`, {  observe: "response" }).pipe(
    map(response => response.body),

  ); }


  addPlace(pl: any): Observable<any> {
    return this.http.post(`${this.config.bakekaUrl}places/addPlace`, pl, {  observe: "response" }).pipe(
    map(response => response.body),

  ); }

  addPlaceMedia(pl: any): Observable<any> {
    return this.http.post(`${this.config.bakekaUrl}places/addPlaceMedia`, pl, {  observe: "response" }).pipe(
    map(response => response.body),

  ); }

  updatePlace(pl: any): Observable<any> {
    return this.http.post(`${this.config.bakekaUrl}places/updatePlace`, pl, {  observe: "response" }).pipe(
    map(response => response.body),

  ); }

  
  deletePlace(plc_id: number, deletelist: any, ): Observable<any> {
    return this.http.post(`${this.config.bakekaUrl}places/deletePlace/${plc_id}`, deletelist, {  observe: "response" }).pipe(
    map(response => response.body),

  ); }

  // audio
   getAudio(aud_id: number): Observable<any> {
        return this.http.get(`${this.config.bakekaUrl}audio/get/${aud_id}`, {  observe: "response" }).pipe(
        map(response => response.body),
    ); }

  getAudiobyUUID(aud_uuid: string): Observable<any> {
      return this.http.get(`${this.config.bakekaUrl}audio/getbyUUID/${aud_uuid}`, {  observe: "response" }).pipe(
      map(response => response.body),
  );}

  
}