import { useRetainingStore } from "@/providers/retaining-store-provider";

import type { UserSubscriptionActionPayload } from "./types";

/**
 * Hook to get current retaining journey data
 */
export function useRetainingJourneyData() {
  const { journey } = useRetainingStore(state => state);

  return {
    journey,
    hasJourney: !!journey,
    getJourneyPayload: () => journey || undefined,
  };
}

/**
 * Helper to create subscription action payload with optional retaining journey data
 */
export function createSubscriptionActionPayload(
  subscriptionId: string,
  action: UserSubscriptionActionPayload["action"],
  journey?: UserSubscriptionActionPayload["retainingJourney"]
): UserSubscriptionActionPayload {
  const payload: UserSubscriptionActionPayload = {
    subscriptionId,
    action,
  };

  if (journey) {
    payload.retainingJourney = journey;
  }

  return payload;
}
