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

import dayjs from 'dayjs/esm';

import { isPresent } from 'app/core/util/operators';
import { ApplicationConfigService } from 'app/core/config/application-config.service';
import { ResilientService, DateTypeEnum } from 'app/resilient/resilient-base/resilient-base.service';
import { createRequestOption } from 'app/core/request/request-util';
import { IPeriodVersion, NewPeriodVersion } from '../period-version.model';

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

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

  /* ResilientService - Service Methods */
  /* ********************************** */
  private readonly resourceUrl = this.applicationConfigService.getEndpointFor('api/period-versions');
  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; }
  
  /* PeriodVersionService - Service methods */
  /* ************************************** */
  queryByPeriod(periodId: number): Observable<EntityArrayResponseType> {
    return this.http.get<IPeriodVersion[]>(`${this.resourceUrl}/byPeriod/${periodId}`, { observe: 'response' });
  }
}
