import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { PROVIDERS_API_ROUTES } from '../constants';
import { IProviderRawResponse, IProviderRequest, IProviderResponse } from '../models';

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

  private apiRoutes = PROVIDERS_API_ROUTES;

  getAll(): Observable<IPaginatedResponse<IProviderResponse>> {
    return this.http.get<IPaginatedResponse<IProviderRawResponse>>(this.apiRoutes.list());
  }
  getSingle(userId: string): Observable<IProviderResponse> {
    return this.http.get<IProviderRawResponse>(this.apiRoutes.single(userId));
  }

  create(userData: IProviderRequest): Observable<IProviderResponse> {
    return this.http.post<IProviderResponse>(this.apiRoutes.list(), userData);
  }

  update(userId: string, userData: IProviderRequest): Observable<IProviderResponse> {
    return this.http.patch<IProviderResponse>(this.apiRoutes.single(userId), userData);
  }
}
