import { getApiBaseUrl } from "@/components/main/BaseUrl";

export type ExploreInteractionPayload = {
  targetType: "post" | "profile" | "academy";
  targetId: string;
  authorId?: string;
  contentType?: "image" | "video" | "academy";
  action?:
    | "view"
    | "profile_visit"
    | "share"
    | "like"
    | "comment"
    | "offer"
    | "watch_complete"
    | "skip"
    | "dwell";
  dwellMs?: number;
};

export async function trackExploreInteraction(
  payload: ExploreInteractionPayload,
  token: string
): Promise<void> {
  if (!token) return;

  try {
    await fetch(`${getApiBaseUrl()}/users/explore/interaction`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${token}`,
      },
      body: JSON.stringify(payload),
    });
  } catch {
    /* non-blocking */
  }
}
