/**
 * Billing Orchestrator Service
 *
 * Orchestrates billing operations through integration services.
 * Controllers should use this orchestrator instead of integration services directly.
 */

import { Injectable } from "@nestjs/common";
import { WhmcsPaymentService } from "@bff/integrations/whmcs/services/whmcs-payment.service.js";
import { WhmcsSsoService } from "@bff/integrations/whmcs/services/whmcs-sso.service.js";
import type { PaymentMethodList } from "@customer-portal/domain/payments";

type SsoTarget = "view" | "download" | "pay";

@Injectable()
export class BillingOrchestrator {
  constructor(
    private readonly paymentService: WhmcsPaymentService,
    private readonly ssoService: WhmcsSsoService
  ) {}

  /**
   * Get payment methods for a client
   */
  async getPaymentMethods(whmcsClientId: number, userId: string): Promise<PaymentMethodList> {
    return this.paymentService.getPaymentMethods(whmcsClientId, userId);
  }

  /**
   * Invalidate payment methods cache for a user
   */
  async invalidatePaymentMethodsCache(userId: string): Promise<void> {
    return this.paymentService.invalidatePaymentMethodsCache(userId);
  }

  /**
   * Create SSO link for invoice access
   */
  async createInvoiceSsoLink(
    whmcsClientId: number,
    invoiceId: number,
    target: SsoTarget
  ): Promise<string> {
    return this.ssoService.whmcsSsoForInvoice(whmcsClientId, invoiceId, target);
  }
}
