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 {
  IPartnerConsumerRawResponse,
  IPartnerConsumerRequest,
  IPartnerConsumerResponse,
} from '../models';

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

  private apiRoutes = CONSUMERS_API_ROUTES;

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

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

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