import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { GUILDS_API_ROUTES } from '../constants';
import { IGuildRawResponse, IGuildRequest, IGuildResponse } from '../models';

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

  private apiRoutes = GUILDS_API_ROUTES;

  getAll(): Observable<IPaginatedResponse<IGuildResponse>> {
    return this.http.get<IPaginatedResponse<IGuildRawResponse>>(this.apiRoutes.list());
  }
  getSingle(id: string): Observable<IGuildResponse> {
    return this.http.get<IGuildRawResponse>(this.apiRoutes.single(id));
  }

  create(data: IGuildRequest): Observable<IGuildResponse> {
    return this.http.post<IGuildResponse>(this.apiRoutes.list(), data);
  }

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