export const LICENSE_SERVER_URL =
  process.env.NEXT_PUBLIC_LICENSE_SERVER_URL || 'https://licenses.dashcaddy.net';

export async function createCheckoutSession(planCode: string, customerEmail?: string) {
  const response = await fetch(`${LICENSE_SERVER_URL}/api/checkout/session`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ planCode, customerEmail })
  });

  const data = await response.json();

  if (!response.ok || !data?.url) {
    throw new Error(data?.error || 'Unable to start checkout');
  }

  return data;
}
