import { inject, Injectable } from '@angular/core';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';

import { isPresent } from 'app/core/util/operators';
import { ApplicationConfigService } from 'app/core/config/application-config.service';
import { ResilientService } from 'app/resilient/resilient-base/resilient-base.service';
import { createRequestOption } from 'app/core/request/request-util';
import { IOrganization, NewOrganization } from '../organization.model';

export type EntityResponseType = HttpResponse<IOrganization>;
export type EntityArrayResponseType = HttpResponse<IOrganization[]>;

@Injectable({ providedIn: 'root' })
export class OrganizationService extends ResilientService<IOrganization, NewOrganization> {
  protected http = inject(HttpClient);
  protected applicationConfigService = inject(ApplicationConfigService);

  private resourceUrl = this.applicationConfigService.getEndpointFor('api/organizations');
  getResourceUrl(): string { return this.resourceUrl; }

  /**
   * Get all Organizations with the given nature
   * @param nature 
   * @returns 
   */
  queryByNature(nature: string): Observable<EntityArrayResponseType> {
    return this.http.get<IOrganization[]>(`${this.resourceUrl}/byNature/${nature}`, { observe: 'response' });
  }

  /**
   * Get all Organizations with the given nature, restricted to Organizations that allow inputInventory==TRUE
   * @param nature 
   * @returns 
   */
  queryByNatureForInput(nature: string): Observable<EntityArrayResponseType> {
    return this.http.get<IOrganization[]>(`${this.resourceUrl}/byNature/forInput/${nature}`, { observe: 'response' });
  }

  /**
   * Get all Organizations with the given nature, within the user access hierarchy
   * @param nature 
   * @returns 
   */
  queryByNatureAndHierarchy(nature: string): Observable<EntityArrayResponseType> {
    return this.http.get<IOrganization[]>(`${this.resourceUrl}/hierarchy/${nature}`, { observe: 'response' });
  }

  /**
   * Get all Organizations with the given nature, within the user access hierarchy, restricted to Organizations that allow inputInventory==TRUE
   * @param nature 
   * @returns 
   */
  queryByNatureAndHierarchyForInput(nature: string): Observable<EntityArrayResponseType> {
    return this.http.get<IOrganization[]>(`${this.resourceUrl}/hierarchy/forInput/${nature}`, { observe: 'response' });
  }
}
