import { HttpClient } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { Seller } from '../models/seller.model';
import { SellerUser } from '../models/seller-user.model';
import { SellerGateway } from './seller-gateway.interface';

/** Contract: docs/backend/PHASE-5-SELLER-PORTAL-CONTRACT.md §3. */
@Injectable({ providedIn: 'root' })
export class SellerApiGateway implements SellerGateway {
  private readonly http = inject(HttpClient);

  loadSellers(): Observable<Seller[]> {
    // §3 defines GET /api/seller/v1/profile (the acting seller's own record).
    // An admin-side list-all-sellers endpoint isn't in this contract; inferred
    // at the conventional admin collection path pending that being specified.
    return this.http.get<Seller[]>('/api/admin/v2/sellers');
  }

  loadTeam(sellerId: string): Observable<SellerUser[]> {
    // §3's GET /api/seller/v1/team is scoped to the caller's own session, not
    // parameterized by sellerId. Using the admin-side sub-resource path so
    // an admin looking at a specific seller's team has a real endpoint to
    // call; revisit if the backend exposes this differently.
    return this.http.get<SellerUser[]>(`/api/admin/v2/sellers/${encodeURIComponent(sellerId)}/team`);
  }
}
