import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { CONSUMER_Accounts_API_ROUTES as CONSUMER_ACCOUNTS_API_ROUTES } from '../constants';
import { IAccountRawResponse, IAccountRequest, IAccountResponse } from '../models';

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

  private apiRoutes = CONSUMER_ACCOUNTS_API_ROUTES;

  getAll(): Observable<IPaginatedResponse<IAccountResponse>> {
    return this.http.get<IPaginatedResponse<IAccountRawResponse>>(this.apiRoutes.list());
  }
  getSingle(accountId: string): Observable<IAccountResponse> {
    return this.http.get<IAccountRawResponse>(this.apiRoutes.single(accountId));
  }

  update(accountId: string, userData: IAccountRequest): Observable<IAccountResponse> {
    return this.http.patch<IAccountResponse>(this.apiRoutes.single(accountId), userData);
  }
}
