import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { USERS_API_ROUTES } from '../constants';
import { IUserRawResponse, IUserRequest, IUserResponse } from '../models';

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

  private apiRoutes = USERS_API_ROUTES;

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

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

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