import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { BUSINESS_ACTIVITY_COMPLEXES_API_ROUTES } from '../constants/apiRoutes/businessActivityComplexes';
import { IComplexRawResponse, IComplexRequest, IComplexResponse } from '../models';

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

  private apiRoutes = BUSINESS_ACTIVITY_COMPLEXES_API_ROUTES;

  getAll(
    consumerId: string,
    businessActivityId: string,
  ): Observable<IPaginatedResponse<IComplexResponse>> {
    return this.http.get<IPaginatedResponse<IComplexRawResponse>>(
      this.apiRoutes.list(consumerId, businessActivityId),
    );
  }
  getSingle(
    consumerId: string,
    businessActivityId: string,
    complexId: string,
  ): Observable<IComplexResponse> {
    return this.http.get<IComplexRawResponse>(
      this.apiRoutes.single(consumerId, businessActivityId, complexId),
    );
  }

  create(
    consumerId: string,
    businessActivityId: string,
    data: IComplexRequest,
  ): Observable<IComplexResponse> {
    return this.http.post<IComplexRawResponse>(
      this.apiRoutes.list(consumerId, businessActivityId),
      data,
    );
  }

  update(
    consumerId: string,
    businessActivityId: string,
    complexId: string,
    data: IComplexRequest,
  ): Observable<IComplexResponse> {
    return this.http.patch<IComplexRawResponse>(
      this.apiRoutes.single(consumerId, businessActivityId, complexId),
      data,
    );
  }
}
