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 { DATE_FORMAT } from 'app/config/input.constants';
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 { IInventory, NewInventory } from '../inventory.model';

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

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

  /* ResilientService - Service Methods */
  /* ********************************** */
  private readonly resourceUrl = this.applicationConfigService.getEndpointFor('api/inventory');
  override getResourceUrl(): string { return this.resourceUrl; }
  
  private readonly dateProperties: Map<string, string> = new Map([
      ["dataDate", DateTypeEnum.DATE],
      ["changeDate", DateTypeEnum.TIMESTAMP],
      ["creationDate", DateTypeEnum.TIMESTAMP]
  ]);
  override getDateProperties(): Map<string, string> { return this.dateProperties; }

  export(req?: any): Observable<Blob> {
    const options = createRequestOption(req);

    return this.http.get(`${this.resourceUrl}/export`, { params: options, responseType: 'blob' });
  }
}
