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 } from '../constants';
import {
  IConsumerAccountRawResponse,
  IConsumerAccountRequest,
  IConsumerAccountResponse,
} from '../models';

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

  private apiRoutes = CONSUMER_ACCOUNTS_API_ROUTES;

  getAll(consumerId: string): Observable<IPaginatedResponse<IConsumerAccountResponse>> {
    return this.http.get<IPaginatedResponse<IConsumerAccountRawResponse>>(
      this.apiRoutes.list(consumerId),
    );
  }
  getSingle(consumerId: string, accountId: string): Observable<IConsumerAccountResponse> {
    return this.http.get<IConsumerAccountRawResponse>(this.apiRoutes.single(consumerId, accountId));
  }

  create(consumerId: string, data: IConsumerAccountRequest): Observable<IConsumerAccountResponse> {
    return this.http.post<IConsumerAccountResponse>(this.apiRoutes.list(consumerId), data);
  }

  update(
    consumerId: string,
    accountId: string,
    data: IConsumerAccountRequest,
  ): Observable<IConsumerAccountResponse> {
    return this.http.patch<IConsumerAccountResponse>(
      this.apiRoutes.single(consumerId, accountId),
      data,
    );
  }
}
