import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { PARTNER_ACCOUNTS_API_ROUTES } from '../constants';
import {
  IPartnerAccountRawResponse,
  IPartnerAccountRequest,
  IPartnerAccountResponse,
} from '../models';

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

  private apiRoutes = PARTNER_ACCOUNTS_API_ROUTES;

  getAll(partnerId: string): Observable<IPaginatedResponse<IPartnerAccountResponse>> {
    return this.http.get<IPaginatedResponse<IPartnerAccountRawResponse>>(
      this.apiRoutes.list(partnerId),
    );
  }
  getSingle(partnerId: string, accountId: string): Observable<IPartnerAccountResponse> {
    return this.http.get<IPartnerAccountRawResponse>(this.apiRoutes.single(partnerId, accountId));
  }

  create(partnerId: string, data: IPartnerAccountRequest): Observable<IPartnerAccountResponse> {
    return this.http.post<IPartnerAccountResponse>(this.apiRoutes.list(partnerId), data);
  }

  update(
    partnerId: string,
    accountId: string,
    data: IPartnerAccountRequest,
  ): Observable<IPartnerAccountResponse> {
    return this.http.patch<IPartnerAccountResponse>(
      this.apiRoutes.single(partnerId, accountId),
      data,
    );
  }
}
