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

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

  private apiRoutes = CONSUMER_LICENSES_API_ROUTES;

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

  update(
    consumerId: string,
    licenseId: string,
    data: ILicenseRequest,
  ): Observable<ILicenseResponse> {
    return this.http.patch<ILicenseRawResponse>(this.apiRoutes.single(consumerId, licenseId), data);
  }
}
