import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { COMPLEX_POSES_API_ROUTES } from '../constants/apiRoutes/complexPoses';
import { IPosRawResponse, IPosRequest, IPosResponse } from '../models';

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

  private apiRoutes = COMPLEX_POSES_API_ROUTES;

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

  create(
    businessActivityId: string,
    complexId: string,
    data: IPosRequest,
  ): Observable<IPosResponse> {
    return this.http.post<IPosRawResponse>(
      this.apiRoutes.list(businessActivityId, complexId),
      data,
    );
  }

  update(
    businessActivityId: string,
    complexId: string,
    posId: string,
    data: IPosRequest,
  ): Observable<IPosResponse> {
    return this.http.patch<IPosRawResponse>(
      this.apiRoutes.single(businessActivityId, complexId, posId),
      data,
    );
  }
}
