// 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 ReservationService {

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


    cart_get(cmp_id: number, lang: string): Observable<any>{
        return this.http.get(`${this.config.bakekaUrl}cart/cart_get/${cmp_id}/${lang}`, {  observe: "response" }).pipe(
        map(response => response.body),
    );}

    reservation_add(reservation: any): Observable<any>{
        return this.http.post(`${this.config.bakekaUrl}cart/reservation_add`, reservation, {  observe: "response" }).pipe(
        map(response => response.body),
    );}

    update_cart(reservation: any): Observable<any>{
        return this.http.post(`${this.config.bakekaUrl}cart/update_cart`, reservation, {  observe: "response" }).pipe(
        map(response => response.body),
    );}

    // ORDINI
  
    get_orders_list(filter: any): Observable<any> {
        return this.http.post(`${this.config.bakekaUrl}orders/orders_list`, filter, { observe: 'response' }).pipe(
          map((response) => response.body),
    ); }

    order_upd_state(ord_id: number, state: number): Observable<any> {
        return this.http.post(`${this.config.bakekaUrl}orders/order_upd_state/${ord_id}`, state, {  observe: "response" }).pipe(
        map(response => response.body),
    
    ); }

    detailorder(ord_id: number, section: string): Observable<any> {
        return this.http.get(`${this.config.bakekaUrl}orders/detailorder/${ord_id}/${section}`, {  observe: "response" }).pipe(
        map(response => response.body),

    ); }

    /*orderstate(section: string): Observable<any> {
        return this.http.get(`${this.config.onlineshopurl}orders/orderstate/${section}`, {  observe: "response" }).pipe(
        map(response => response.body),

    ); }*/
    
  
}