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 { IUnit, NewUnit } from '../unit.model';

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

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

  private resourceUrl = this.applicationConfigService.getEndpointFor('api/units');
  getResourceUrl(): string { return this.resourceUrl; }
  
  queryByType(unitTypeId: number): Observable<EntityArrayResponseType> {
    return this.http.get<IUnit[]>(`${this.resourceUrl}/byType/${unitTypeId}`, { observe: 'response' });
  }
  
  queryForVariable(variableId: number): Observable<EntityArrayResponseType> {
    return this.http.get<IUnit[]>(`${this.resourceUrl}/forVariable/${variableId}`, { observe: 'response' });
  }
}
