import { registerAs } from "@nestjs/config";

export default registerAs("waafi", () => ({
  // `/asm` is appended in the provider; use sandbox by default, switch to
  // https://api.waafipay.net in production.
  baseUrl: process.env.WAAFI_BASE_URL ?? "https://sandbox.waafipay.net",
  // HPP credentials (Hosted Payment Page family).
  merchantUid: process.env.WAAFI_MERCHANT_UID ?? "",
  storeId: process.env.WAAFI_STORE_ID ?? "",
  hppKey: process.env.WAAFI_HPP_KEY ?? "",
  // HMAC secret returned once by WEBHOOK_REGISTER; verifies inbound webhooks.
  webhookSecret: process.env.WAAFI_WEBHOOK_SECRET ?? "",
  // Wallet payment method (EVC/ZAAD/Sahal) — MWALLET_ACCOUNT requires the payer phone up front.
  paymentMethod: process.env.WAAFI_PAYMENT_METHOD ?? "MWALLET_ACCOUNT",
  // Waafi has no ETB; when set this overrides the asserted currency (USD/DJF/SLSH).
  // TODO(demo): revert to the env-driven line below after the demo. Temporarily FORCED to USD
  // here so the .env (WAAFI_CURRENCY) cannot override it.
  // currency: process.env.WAAFI_CURRENCY ?? "DJF",
  currency: "USD",
  // Browser redirect targets after the hosted page completes/fails (UX only; webhook is source of truth).
  successUrl: process.env.WAAFI_HPP_SUCCESS_URL ?? "",
  failureUrl: process.env.WAAFI_HPP_FAILURE_URL ?? "",
  // Callback data format: 1 = POST, 2 = GET, 4 = Result Token.
  respDataFormat: Number(process.env.WAAFI_HPP_RESP_FORMAT ?? "1"),
  // Registered webhook URL (reference only; registration is performed out-of-band).
  notifyUrl: process.env.WAAFI_NOTIFY_URL ?? "",
  // DEV ONLY: disable TLS cert verification. The Waafi sandbox serves a *.waafi.com cert that
  // does not match sandbox.waafipay.net (ERR_TLS_CERT_ALTNAME_INVALID). Never enable in prod.
  insecureTls: process.env.WAAFI_INSECURE_TLS === "true",
}));
