import { Injectable } from '@angular/core';
import { StruttureControllerUploadFiles$Params } from '@api/fn/strutture/strutture-controller-upload-files';
import { StruttureApiClient } from '@api/services/strutture-api-client';
import { UtilsService } from '@core/services/utils.service';
import { MessageService } from 'primeng/api';
import { catchError, throwError } from 'rxjs';

@Injectable({
  providedIn: 'root',
})
export class UploadDocumentazioneService {
  constructor(
    private utilsService: UtilsService,
    private struttureApiClient: StruttureApiClient,
    private readonly messageService: MessageService,
  ) {}

  uploadDocumentazione(params: StruttureControllerUploadFiles$Params) {
    return this.struttureApiClient.struttureControllerUploadFiles(params).pipe(
      catchError((err: unknown) => {
        this.messageService.add({
          severity: 'error',
          summary: 'Oops, qualcosa è andato storto!',
          detail: `Riprova più tardi`,
        });
        return throwError(() => err);
      }),
    );
  }
}
