import { UserSubscriptionActionEnum } from "@/entities/subscriptions/types";

const ROOT_ROUTE = "/";
const ROOT_ROUTE_V2 = "/v2/";
const ROOT_ROUTE_V3 = "/v3/";

const createRoute = (
  segments: string[],
  rootRoute: string = ROOT_ROUTE
): string => {
  return rootRoute + segments.join("/");
};

export const API_ROUTES = {
  dashboard: () => createRoute(["dashboard"]),
  videoGuides: () => createRoute(["video-guides"], ROOT_ROUTE_V2),
  videoGuide: (id: string) => createRoute(["video-guides", id], ROOT_ROUTE_V2),
  checkVideoGuidePurchase: (productKey: string) =>
    createRoute(["products", "video-guides", productKey, "check-purchase"]),
  subscriptions: () => createRoute(["payment", "subscriptions"], ROOT_ROUTE_V3),
  paymentCheckout: () => createRoute(["payment", "checkout"], ROOT_ROUTE_V2),
  paymentSingleCheckout: () => createRoute(["payment", "checkout"]),
  usersMe: () => createRoute(["users", "me"], ROOT_ROUTE),
  compatibilityActionFields: (id: string) =>
    createRoute(["dashboard", "compatibility-actions", id, "fields"]),
  startGeneration: () => createRoute(["generations", "start"]),
  statusGeneration: (id: string) => createRoute(["generations", "status", id]),
  userSubscriptionAction: (
    subscriptionId: string,
    action: UserSubscriptionActionEnum
  ) =>
    createRoute(
      ["payment", "subscriptions", subscriptionId, action],
      ROOT_ROUTE_V3
    ),

  // session
  funnel: () => createRoute(["session", "funnel"], ROOT_ROUTE_V2),

  // chats
  createAllChats: () => createRoute(["chats", "create-all"]),
  createChat: (assistantId: string) =>
    createRoute(["chats", "create", assistantId]),
  getChatsList: () => createRoute(["chats", "list"]),
  getChatMessages: (chatId: string) =>
    createRoute(["chats", chatId, "messages"]),
  getUserBalance: () => createRoute(["chats", "balance"]),
  getMyChatSettings: () => createRoute(["chats", "profile", "chat-settings"]),
  updateMyChatSettings: () =>
    createRoute(["chats", "profile", "chat-settings"]),
};
