import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { CONSUMER_CUSTOMERS_API_ROUTES } from '../constants';
import { ICustomerRawResponse, ICustomerRequest, ICustomerResponse } from '../models';

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

  private apiRoutes = CONSUMER_CUSTOMERS_API_ROUTES;

  getAll(): Observable<IPaginatedResponse<ICustomerResponse>> {
    return this.http.get<IPaginatedResponse<ICustomerRawResponse>>(this.apiRoutes.list());
  }
  getSingle(customerId: string): Observable<ICustomerResponse> {
    return this.http.get<ICustomerRawResponse>(this.apiRoutes.single(customerId));
  }

  updateIndividualCustomer(
    customerId: string,
    data: ICustomerRequest,
  ): Observable<ICustomerResponse> {
    return this.http.patch<ICustomerResponse>(this.apiRoutes.updateIndividual(customerId), data);
  }
  updateLegalCustomer(customerId: string, data: ICustomerRequest): Observable<ICustomerResponse> {
    return this.http.patch<ICustomerResponse>(this.apiRoutes.updateLegal(customerId), data);
  }
}
