/**
 * Resolve the per-port branding shell for transactional emails.
 *
 * Senders that have a portId call this once and pass the result into
 * the email template. Senders without a portId (e.g. CRM invite at
 * create-time before a port is selected) pass null - the shell then
 * falls back to neutral defaults (no logo, plain background, slate
 * accent). Configure per-port branding via /admin/branding.
 */

import { getPortBrandingConfig } from '@/lib/services/port-config';
import type { BrandingShell } from '@/lib/email/shell';

export async function getBrandingShell(
  portId: string | null | undefined,
): Promise<BrandingShell | null> {
  if (!portId) return null;
  try {
    const cfg = await getPortBrandingConfig(portId);
    return {
      logoUrl: cfg.logoUrl,
      backgroundUrl: cfg.emailBackgroundUrl,
      primaryColor: cfg.primaryColor,
      emailHeaderHtml: cfg.emailHeaderHtml,
      emailFooterHtml: cfg.emailFooterHtml,
    };
  } catch {
    return null;
  }
}
