import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { CONSUMER_BUSINESS_ACTIVITY_GOODS_API_ROUTES } from '../constants/apiRoutes/businessActivityGoods';
import {
  IConsumerBusinessActivityGoodRawResponse,
  IConsumerBusinessActivityGoodResponse,
} from '../models/goods_io';

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

  private apiRoutes = CONSUMER_BUSINESS_ACTIVITY_GOODS_API_ROUTES;

  getAll(
    businessId: string,
  ): Observable<IPaginatedResponse<IConsumerBusinessActivityGoodResponse>> {
    return this.http.get<IPaginatedResponse<IConsumerBusinessActivityGoodRawResponse>>(
      this.apiRoutes.list(businessId),
    );
  }
  getSingle(businessId: string, id: string): Observable<IConsumerBusinessActivityGoodResponse> {
    return this.http.get<IConsumerBusinessActivityGoodRawResponse>(
      this.apiRoutes.single(businessId, id),
    );
  }

  create(businessId: string, data: FormData): Observable<IConsumerBusinessActivityGoodResponse> {
    return this.http.post<IConsumerBusinessActivityGoodResponse>(
      this.apiRoutes.list(businessId),
      data,
    );
  }

  update(
    businessId: string,
    id: string,
    data: FormData,
  ): Observable<IConsumerBusinessActivityGoodResponse> {
    return this.http.patch<IConsumerBusinessActivityGoodResponse>(
      this.apiRoutes.single(businessId, id),
      data,
    );
  }
}
