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 ConsumerComplexesService {
  constructor(private http: HttpClient) {}

  private apiRoutes = BUSINESS_ACTIVITY_COMPLEXES_API_ROUTES;

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

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

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