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 { IVariable, NewVariable } from '../variable.model';
import { IUnit } from 'app/entities/unit/unit.model';


export type PartialUpdateVariable = Partial<IVariable> & Pick<IVariable, 'id'>;

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

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

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

  queryForBaseUnit(variableId: number): Observable<HttpResponse<IUnit>> {
    return this.http.get<IUnit>(`${this.resourceUrl}/${variableId}/baseUnit`, { observe: 'response' });
  }

  queryForManualInput(): Observable<HttpResponse<IVariable[]>> {
    return this.http.get<IVariable[]>(`${this.resourceUrl}/forManualInput`, { observe: 'response' });
  }

  export(): Observable<Blob> {
    return this.http.get(`${this.resourceUrl}/export`, { responseType: 'blob' });
  }
}
