import { HttpClient } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable<% if (hasMappedResult) { %>, map<% } %> } from 'rxjs';
<% if (models) { %>import { <%= classify(entity) %>Dto } from './<%= dasherize(entity) %>.dto';
import { <%= classify(entity) %> } from './<%= dasherize(entity) %>.model';
<% if (mapper) { %>import { map<%= classify(entity) %>Dto, map<%= classify(entity) %>ToDto } from './<%= dasherize(entity) %>.mapper';
<% } %><% } else { %>
export interface <%= classify(entity) %> {
  id: string;
}

interface <%= classify(entity) %>Dto {
  id: string;
}
<% } %>
@Injectable({ providedIn: 'root' })
export class <%= classify(name) %>Api {
  private readonly http = inject(HttpClient);
  private readonly baseUrl = <%= baseUrlLiteral %>;

<% if (hasList) { %>  list(): Observable<readonly <%= classify(entity) %>[]> {
    return this.http.get<readonly <%= classify(entity) %>Dto[]>(this.baseUrl)<% if (mapper) { %>.pipe(
      map((items) => items.map(map<%= classify(entity) %>Dto)),
    )<% } %>;
  }

<% } %><% if (hasGet) { %>  get(id: string): Observable<<%= classify(entity) %>> {
    return this.http.get<<%= classify(entity) %>Dto>(`${this.baseUrl}/${encodeURIComponent(id)}`)<% if (mapper) { %>.pipe(
      map(map<%= classify(entity) %>Dto),
    )<% } %>;
  }

<% } %><% if (hasCreate) { %>  create(value: Omit<<%= classify(entity) %>, 'id'>): Observable<<%= classify(entity) %>> {
    return this.http.post<<%= classify(entity) %>Dto>(this.baseUrl, <% if (mapper) { %>map<%= classify(entity) %>ToDto(value)<% } else { %>value<% } %>)<% if (mapper) { %>.pipe(
      map(map<%= classify(entity) %>Dto),
    )<% } %>;
  }

<% } %><% if (hasUpdate) { %>  update(id: string, value: <%= classify(entity) %>): Observable<<%= classify(entity) %>> {
    return this.http.put<<%= classify(entity) %>Dto>(
      `${this.baseUrl}/${encodeURIComponent(id)}`,
      <% if (mapper) { %>map<%= classify(entity) %>ToDto(value)<% } else { %>value<% } %>,
    )<% if (mapper) { %>.pipe(map(map<%= classify(entity) %>Dto))<% } %>;
  }

<% } %><% if (hasDelete) { %>  delete(id: string): Observable<void> {
    return this.http.delete<void>(`${this.baseUrl}/${encodeURIComponent(id)}`);
  }
<% } %>}
