import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { GUILD_GOODS_API_ROUTES } from '../constants/apiRoutes/goods';
import { IGuildGoodsRawResponse, IGuildGoodsResponse } from '../models';

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

  private apiRoutes = GUILD_GOODS_API_ROUTES;

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

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

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