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 { IOutputData, NewOutputData } from '../output-data.model';

export type PartialUpdateOutputData = Partial<IOutputData> & Pick<IOutputData, 'id'>;

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

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

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

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