import {
  httpGetRequest,
  httpPutRequest,
  httpDeleteRequest,
  APIUrlGenerator,
} from "@/utils/baseHttpService";
import { API_ROUTES } from "@/constant/routes";
import {
  ProductCommentFilters,
  ProductCommentsResponse,
  UpdateCommentStatusRequest,
  UpdateCommentStatusResponse,
  DeleteCommentResponse,
} from "./_models";

export const getProductComments = async (
  filters: ProductCommentFilters
): Promise<ProductCommentsResponse> => {
  const queryParams: Record<string, string | number> = {};
  
  if (filters.status) queryParams.status = filters.status;
  if (filters.productId) queryParams.productId = filters.productId;
  if (filters.userId) queryParams.userId = filters.userId;
  queryParams.limit = filters.limit;
  queryParams.offset = filters.offset;

  const response = await httpGetRequest<ProductCommentsResponse>(
    APIUrlGenerator(API_ROUTES.GET_PRODUCT_COMMENTS, queryParams)
  );
  return response.data;
};

export const updateCommentStatus = async (
  commentId: string,
  payload: UpdateCommentStatusRequest
): Promise<UpdateCommentStatusResponse> => {
  const response = await httpPutRequest<UpdateCommentStatusResponse>(
    APIUrlGenerator(API_ROUTES.UPDATE_COMMENT_STATUS(commentId)),
    payload
  );
  return response.data;
};

export const deleteComment = async (
  commentId: string
): Promise<DeleteCommentResponse> => {
  const response = await httpDeleteRequest<DeleteCommentResponse>(
    APIUrlGenerator(API_ROUTES.DELETE_COMMENT(commentId))
  );
  return response.data;
};

