/**
 * Fire-and-forget view tracking.
 * type: 1=Article, 2=Clips, 3=Live News, 4=Show, 5=Story, 7=EPaper
 * video_id: pass the show's video ID for type 4; pass 0 for all other types.
 */
export async function addView(
  type: number,
  contentId: number,
  userId: number,
  videoId = 0,
): Promise<void> {
  if (!contentId) return;
  try {
    const [{ default: apiClient }, { API_ENDPOINTS }] = await Promise.all([
      import("@/services/api.client"),
      import("@/lib/constants/apiEndpoints"),
    ]);
    await apiClient.post(API_ENDPOINTS.ADD_VIEW, {
      user_id: userId,
      type,
      content_id: contentId,
      video_id: type === 4 ? videoId : 0,
    });
  } catch {
    // silently ignore — view tracking should never break the UI
  }
}
