import apiClient from "@/lib/axiosClient";
import { API_ENDPOINTS } from "@/lib/apiEndpoints";

/** Reaction status values sent to the API */
export const LIKE_STATUS = {
  REMOVE: 0,   // remove any existing reaction
  LIKE: 1,     // like
  DISLIKE: 2,  // dislike
} as const;

export type LikeStatus = typeof LIKE_STATUS[keyof typeof LIKE_STATUS];

export interface LikeResponse {
  status: number;
  message: string;
  result: unknown[];
}

/**
 * Add, remove, or change a like/dislike reaction on any content.
 *
 * @param contentId   Numeric string ID of the content.
 * @param contentType content_type value (1=video, 2=music, 3=reel, 4=podcast …).
 * @param status      0=remove, 1=like, 2=dislike.
 * @param episodeId   Episode ID for podcasts; pass 0 for non-episode content.
 */
export const likeService = {
  react: (
    contentId: string | number,
    contentType: number,
    status: LikeStatus,
    episodeId = 0,
  ): Promise<LikeResponse> =>
    apiClient
      .post(API_ENDPOINTS.ADD_REMOVE_LIKE_DISLIKE, {
        content_id: contentId,
        content_type: contentType,
        status,
        episode_id: episodeId,
      })
      .then((r) => r.data),
};
