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

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

  private apiRoutes = PARTNER_LICENSES_API_ROUTES;

  getAll(paginationQuery?: IPaginatedQuery): Observable<IPaginatedResponse<ILicenseResponse>> {
    return this.http.get<IPaginatedResponse<ILicenseRawResponse>>(this.apiRoutes.list(), {
      params: {
        page: paginationQuery?.page || '1',
        perPage: paginationQuery?.pageSize || '50',
      },
    });
  }

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