/**
 * Meta (Facebook & Instagram) Graph API & Conversions API Configuration.
 */

export const META_CONFIG = {
  graphVersion:
    process.env.NEXT_PUBLIC_META_GRAPH_VERSION ||
    process.env.META_GRAPH_VERSION ||
    'v20.0',
  partnerAgent: process.env.META_PARTNER_AGENT || 'shopify_meta_commerce_connector',
  defaultTestEventCode: process.env.META_TEST_EVENT_CODE || 'TEST_DIGI_HORIZON',

  // Endpoints
  baseUrl: 'https://graph.facebook.com',
  get graphBaseUrl(): string {
    return `https://graph.facebook.com/${this.graphVersion}`;
  },
  getGraphApiUrl: (version?: string) => `https://graph.facebook.com/${version || META_CONFIG.graphVersion}`,

  // Server-only access helpers
  getServerAppId: () => process.env.META_APP_ID || '',
  getServerAppSecret: () => process.env.META_APP_SECRET || '',
  getServerSystemToken: () => process.env.META_ACCESS_TOKEN || '',
} as const;

export function buildMetaGraphUrl(path: string, version?: string): string {
  const cleanPath = path.startsWith('/') ? path : `/${path}`;
  const v = version || META_CONFIG.graphVersion;
  return `https://graph.facebook.com/${v}${cleanPath}`;
}
