import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { BUSINESS_ACTIVITIES_API_ROUTES } from '../constants/apiRoutes/businessActivities';
import {
  IBusinessActivityRawResponse,
  IBusinessActivityRequest,
  IBusinessActivityResponse,
} from '../models';

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

  private apiRoutes = BUSINESS_ACTIVITIES_API_ROUTES;

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

  create(
    consumerId: string,
    data: IBusinessActivityRequest,
  ): Observable<IBusinessActivityResponse> {
    return this.http.post<IBusinessActivityRawResponse>(this.apiRoutes.list(consumerId), data);
  }

  update(
    consumerId: string,
    businessActivityId: string,
    data: IBusinessActivityRequest,
  ): Observable<IBusinessActivityResponse> {
    return this.http.patch<IBusinessActivityRawResponse>(
      this.apiRoutes.single(consumerId, businessActivityId),
      data,
    );
  }
}
