// 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 { SpinnerService } from 'src/app/_services/SpinnerService';

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

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

  constructor(private config: ConfigService,
              private http: HttpClient,
              /*private spinnerService: SpinnerService,*/) {}


  //lista ordini
  get_orders_list(filter: any): Observable<any> {
      //this.spinnerService.show();
        return this.http.post(`${this.config.onlineshopurl}orders/orders_list`, filter, { observe: 'response' }).pipe(
          map((response) => response.body),
          //finalize(() => this.spinnerService.hide()),
  ); }

  upd_state_order(ord_id: number, type_payment: string, state: number): Observable<any> {
      //this.spinnerService.show();
      return this.http.post(`${this.config.onlineshopurl}orders/upd_state_order/${ord_id}/${type_payment}`, state, {  observe: "response" }).pipe(
      map(response => response.body),
      //finalize(() => this.spinnerService.hide()),
  
    ); }

  orders_dett(ord_id: number, section: string): Observable<any> {
      //this.spinnerService.show();
      return this.http.get(`${this.config.onlineshopurl}orders/orders_dett/${ord_id}/${section}`, {  observe: "response" }).pipe(
      map(response => response.body),
      //finalize(() => this.spinnerService.hide()),

  ); }


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

  ); }

  order_del(ord_id: number): Observable<any>{
    //this.spinnerService.show();
    return this.http.delete(`${this.config.onlineshopurl}orders/order_del/${ord_id}`, {  observe: "response" }).pipe(
      map(response => response.body),
      //finalize(() => this.spinnerService.hide()),
  ); }

  stampa(cmp_id: number,lang: string, ord_id: number, section: string): Observable<any> {
     //this.spinnerService.show();
      return this.http.get(`${this.config.onlineshopurl}orders/orderstampa/${cmp_id}/${lang}/${ord_id}/${section}`, {  observe: "response" }).pipe(
      map(response => response.body),
      //finalize(() => this.spinnerService.hide()),
  ); }


}
