import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { PARTNERS_API_ROUTES } from '../constants';
import { IPartnerRawResponse, IPartnerResponse } from '../models';

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

  private apiRoutes = PARTNERS_API_ROUTES;

  getAll(): Observable<IPaginatedResponse<IPartnerResponse>> {
    return this.http.get<IPaginatedResponse<IPartnerRawResponse>>(this.apiRoutes.list());
  }
  getSingle(partnerId: string): Observable<IPartnerResponse> {
    return this.http.get<IPartnerRawResponse>(this.apiRoutes.single(partnerId));
  }

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

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