import { IListingResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { POS_OWNED_GOODS_API_ROUTES } from '../constants';
import { IPosGoodsManagementRawResponse, IPosGoodsManagementResponse } from '../models';

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

  private apiRoutes = POS_OWNED_GOODS_API_ROUTES;

  getAll(): Observable<IListingResponse<IPosGoodsManagementResponse>> {
    return this.http.get<IListingResponse<IPosGoodsManagementRawResponse>>(this.apiRoutes.getAll());
  }

  get(goodId: string): Observable<IPosGoodsManagementResponse> {
    return this.http.get<IPosGoodsManagementRawResponse>(this.apiRoutes.get(goodId));
  }

  create(data: FormData): Observable<IPosGoodsManagementResponse> {
    return this.http.post<IPosGoodsManagementRawResponse>(this.apiRoutes.create(), data);
  }

  update(goodId: string, payload: FormData): Observable<IPosGoodsManagementResponse> {
    return this.http.patch<IPosGoodsManagementRawResponse>(this.apiRoutes.update(goodId), payload);
  }
}
