import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { FxQuote } from '../models/fx-quote.model';
import { FxQuoteGateway } from './fx-quote-gateway.interface';

/**
 * Real FX gateway. Contract: docs/backend/PHASE-1-MONEY-FX-PAYMENTS-CONTRACT.md §3.1.
 *
 * Deliberately thin: no caching, no retry logic here. TTL/expiry handling is
 * the caller's job (isFxQuoteExpired), because the caller decides what to do
 * with an expired quote (re-fetch vs block checkout) - baking a policy into
 * the gateway would hide that decision.
 */
@Injectable({ providedIn: 'root' })
export class FxQuoteApiGateway implements FxQuoteGateway {
  private readonly http = inject(HttpClient);

  getQuote(base: string, quote: string): Observable<FxQuote> {
    const params = new HttpParams().set('base', base).set('quote', quote);
    return this.http.get<FxQuote>('/api/v2/pricing/fx-quote', { params });
  }
}
