import { Injectable, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DirGroup, } from '../../models/user-management.api.models';
import { ApiService } from './user-management.api.service';
import { Observable } from 'rxjs/internal/Observable';
import Swal from 'sweetalert2';
import { UrlService } from './url.service';

@Injectable({
  providedIn: 'root'
})
export class DirGroupService extends ApiService<DirGroup> {
  constructor(http: HttpClient, urlService : UrlService) {
    super(http, urlService.apiRoute.dirGroup);
  }

  //TODO: Swal.fire
  override getAll(): Observable<DirGroup[]> {
    return new Observable<DirGroup[]>(observer => {
      super.getAll()
        .subscribe({
          next: (response) => {
            observer.next(response)
          },
          error: (error) => {
            Swal.fire({
              icon: "error",
              title: "Oops...",
              text: `Active Directory-Verbindung verloren. Bitte melden Sie sich erneut an`,
            });
            observer.error(error)
          },
          complete: () => observer.complete()
        });
    });
  }
}