import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { GUILD_GOOD_CATEGORIES_API_ROUTES } from '../constants/apiRoutes/goodCategories';
import {
  IGoodCategoriesRawResponse,
  IGoodCategoriesResponse,
  IGoodCategoryRequest,
} from '../models';

@Injectable({ providedIn: 'root' })
export class GuildGoodCategoriesService {
  constructor(private http: HttpClient) {}

  private apiRoutes = GUILD_GOOD_CATEGORIES_API_ROUTES;

  getAll(guildId: string): Observable<IPaginatedResponse<IGoodCategoriesResponse>> {
    return this.http.get<IPaginatedResponse<IGoodCategoriesRawResponse>>(
      this.apiRoutes.list(guildId),
    );
  }
  getSingle(guildId: string, id: string): Observable<IGoodCategoriesResponse> {
    return this.http.get<IGoodCategoriesRawResponse>(this.apiRoutes.single(guildId, id));
  }

  create(guildId: string, data: IGoodCategoryRequest): Observable<IGoodCategoriesResponse> {
    return this.http.post<IGoodCategoriesResponse>(this.apiRoutes.list(guildId), data);
  }

  update(
    guildId: string,
    id: string,
    data: IGoodCategoryRequest,
  ): Observable<IGoodCategoriesResponse> {
    return this.http.patch<IGoodCategoriesResponse>(this.apiRoutes.single(guildId, id), data);
  }
}
