import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { LICENSES_API_ROUTES } from '../constants';
import { ILicenseRawResponse, ILicenseRequest, ILicenseResponse } from '../models';

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

  private apiRoutes = LICENSES_API_ROUTES;

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

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

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