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

import { isPresent } from 'app/core/util/operators';
import { ApplicationConfigService } from 'app/core/config/application-config.service';
import { ResilientService, DateTypeEnum, RestOf } from 'app/resilient/resilient-base/resilient-base.service';
import { createRequestOption } from 'app/core/request/request-util';
import { IResilientLog, NewResilientLog } from '../resilient-log.model';

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

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

  /* ResilientService - Service Methods */
  /* ********************************** */
  private readonly resourceUrl = this.applicationConfigService.getEndpointFor('api/resilient-logs');
  override getResourceUrl(): string { return this.resourceUrl; }
  
  private readonly dateProperties: Map<string, string> = new Map([
      ["creationDate", DateTypeEnum.TIMESTAMP]
  ]);
  override getDateProperties(): Map<string, string> { return this.dateProperties; }
  
  
  findByOwner(id: number): Observable<EntityArrayResponseType> {
    return this.http
      .get<RestOf<IResilientLog>[]>(`${this.resourceUrl}/owner/${id}`, { observe: 'response' })
      .pipe(map(res => this.convertResponseArrayFromServer(res)));
  }
}
