import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { CONSUMERS_API_ROUTES } from '../constants';
import {
  IAdminConsumerRawResponse,
  IAdminConsumerRequest,
  IAdminConsumerResponse,
} from '../models';

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

  private apiRoutes = CONSUMERS_API_ROUTES;

  getAll(): Observable<IPaginatedResponse<IAdminConsumerResponse>> {
    return this.http.get<IPaginatedResponse<IAdminConsumerRawResponse>>(this.apiRoutes.list());
  }
  getSingle(consumerId: string): Observable<IAdminConsumerResponse> {
    return this.http.get<IAdminConsumerRawResponse>(this.apiRoutes.single(consumerId));
  }

  create(userData: IAdminConsumerRequest): Observable<IAdminConsumerResponse> {
    return this.http.post<IAdminConsumerResponse>(this.apiRoutes.list(), userData);
  }

  update(consumerId: string, userData: IAdminConsumerRequest): Observable<IAdminConsumerResponse> {
    return this.http.patch<IAdminConsumerResponse>(this.apiRoutes.single(consumerId), userData);
  }
}
