const ROOT_ROUTE = "/";

const createRoute = (
  segments: Array<string | undefined>,
  queryParams?: Record<string, string>
): string => {
  const url = ROOT_ROUTE + segments.filter(Boolean).join("/");
  if (queryParams) {
    return url + "?" + new URLSearchParams(queryParams).toString();
  }
  return url;
};

const profilePrefix = "profile";
const retainingFunnelPrefix = "retaining";
const emailMarketingPrefix = "em";
const emailMarketingCompatibilityV1Prefix = `${emailMarketingPrefix}/c/v1`;
const emailMarketingSoulmateV1Prefix = `${emailMarketingPrefix}/s/v1`;

export const ROUTES = {
  home: () => createRoute([]),

  // Auth
  authCallback: () => createRoute(["auth", "callback"]),

  // Advisers
  advisers: () => createRoute(["advisers"]),

  // Meditation
  meditation: (id?: string) => createRoute(["meditation", id]),
  meditationResult: (id: string, resultId: string) =>
    createRoute(["meditation", id, "result", resultId]),

  // Compatibility
  compatibility: (id?: string) => createRoute(["compatibility", id]),
  compatibilityResult: (id: string, resultId: string) =>
    createRoute(["compatibility", id, "result", resultId]),

  // Palmistry
  palmistryResult: (id: string) => createRoute(["palmistry", "result", id]),

  // Profile
  profile: () => createRoute([profilePrefix]),
  profileSubscriptions: () => createRoute([profilePrefix, "subscriptions"]),

  // Retaining Funnel
  retainingFunnelCancelSubscription: () =>
    createRoute([retainingFunnelPrefix, "cancel-subscription"]),
  retainingFunnelAppreciateChoice: () =>
    createRoute([retainingFunnelPrefix, "appreciate-choice"]),
  retainingFunnelStay50Done: () =>
    createRoute([retainingFunnelPrefix, "stay-50-done"]),
  retainingFunnelWhatReason: () =>
    createRoute([retainingFunnelPrefix, "what-reason"]),
  retainingFunnelSecondChance: () =>
    createRoute([retainingFunnelPrefix, "second-chance"]),
  retainingFunnelStopFor30Days: () =>
    createRoute([retainingFunnelPrefix, "stop-for-30-days"]),
  retainingFunnelChangeMind: () =>
    createRoute([retainingFunnelPrefix, "change-mind"]),
  retainingFunnelCancellationOfSubscription: () =>
    createRoute([retainingFunnelPrefix, "cancellation-of-subscription"]),
  retainingFunnelPlanCancelled: () =>
    createRoute([retainingFunnelPrefix, "plan-cancelled"]),
  retainingFunnelSubscriptionStopped: () =>
    createRoute([retainingFunnelPrefix, "subscription-stopped"]),
  retainingFunnelFreeChatActivated: () =>
    createRoute([retainingFunnelPrefix, "free-chat-activated"]),

  // Payment
  payment: (queryParams?: Record<string, string>) =>
    createRoute(["payment"], queryParams),
  paymentSuccess: () => createRoute(["payment", "success"]),
  paymentFailed: () => createRoute(["payment", "failed"]),

  // Secret Discount
  saveOff: () => createRoute(["save-off"]),
  secretDiscount: () => createRoute(["secret-discount"]),

  // Chat
  chat: (id?: string) => createRoute(["chat", id]),

  // Additional Purchases
  addConsultant: () => createRoute(["add-consultant"]),
  addGuides: () => createRoute(["add-guides"]),
  additionalPurchases: (type?: string) => createRoute(["ap", type]),

  // Email Marketing Compatibility V1
  emailMarketingCompatibilityV1Landing: () =>
    createRoute([emailMarketingCompatibilityV1Prefix, "landing"]),
  emailMarketingCompatibilityV1SpecialOffer: () =>
    createRoute([emailMarketingCompatibilityV1Prefix, "special-offer"]),

  // Email Marketing Soulmate V1
  emailMarketingSoulmateV1Landing: () =>
    createRoute([emailMarketingSoulmateV1Prefix, "landing"]),
  emailMarketingSoulmateV1SpecialOffer: () =>
    createRoute([emailMarketingSoulmateV1Prefix, "special-offer"]),

  // // Compatibility
  // compatibilities: () => createRoute(["compatibilities"]),

  // // Meditation
  // meditations: () => createRoute(["meditations"]),
};
