using Baya.Application.Contracts.Common;
using Baya.Application.Contracts.Invoices;
using Baya.Application.Contracts.Payments;
using Baya.Infrastructure.CrossCutting.Seams;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Baya.Infrastructure.CrossCutting.ServiceConfiguration;
public static class ServiceCollectionExtension
{
///
/// Registers the cross-cutting seams (time, PII encryption, cache, object storage, SMS) with their
/// in-memory/local mock implementations. Swapping in a real provider later is a registration change
/// here — callers depend only on the Application contracts. (The real in-app
/// INotificationDispatcher needs the database, so it is registered in the Persistence layer.)
///
public static IServiceCollection AddCrossCuttingSeams(this IServiceCollection services, IConfiguration configuration)
{
services.Configure(configuration.GetSection(SeamOptions.SectionName));
services.AddMemoryCache();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
// OTP/SMS delivery rail (backend-phase-2). The mock logs the code; a real gateway client
// (Kavenegar/Ghasedak/SMS.ir) replaces this registration only.
services.AddSingleton();
// استعلام شبا IBAN-owner ↔ national-id inquiry (backend-phase-3). The mock returns a deterministic
// fake match; a real Finnotech/banking-bridge client replaces this registration only.
services.AddSingleton();
// Address geocoding (backend-phase-4). The mock derives deterministic coordinates around the city
// centroid with no network call; a real Neshan/Google geocoding client replaces this registration.
services.AddSingleton();
// Nurse-verification vendors (backend-phase-6). All three are deterministic mocks; a real Iranian
// e-KYC vendor / Shahkar bridge / (future) MoH-INO portal swaps in by a registration change only —
// no mock behaviour is baked into any handler call site.
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
// Payment-capture trigger (backend-phase-9). The mock returns a deterministic succeeded capture so
// ConvertRequestToBooking is testable now; in b10 the real card capture replaces this registration
// and calls ConvertRequestToBooking directly on a real payment_transactions.succeeded.
services.AddSingleton();
// Payments money-path seams (backend-phase-10). All four are deterministic mocks; a real card PSP /
// تسهیم split adapter (config-selected per payment_gateways.config_json), per-provider signature
// verifier, and StackExchange.Redis lock swap in by a registration change only — no mock behaviour is
// baked into any handler. The DB uniques/state-machine remain the authoritative money-path backstop.
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
// Refunds/invoices seams (backend-phase-11). سامانه مودیان e-invoicing is mocked (pending/no-ref by
// default; config can force registered). IBnplProvider is a thin local stub so the bnpl_revert refund
// path runs before b12 merges — b12 owns the real seam. Both swap in by a registration change only.
services.AddSingleton();
services.AddSingleton();
return services;
}
}