import type { ActionFunctionArgs } from "@remix-run/node";
import { authenticate } from "../shopify.server";

export const action = async ({ request }: ActionFunctionArgs) => {
  const { shop, topic, payload } = await authenticate.webhook(request);

  console.log(
    `Received ${topic} webhook for ${shop}:`,
    JSON.stringify(payload, null, 2),
  );

  // Shopify handles subscription state — billing.require() in the loader
  // will enforce payment on next page load. This webhook is for logging
  // and future use (e.g., sending notifications on cancellation).

  return new Response();
};
