import axios from "../../../config/axios";
import { getMailboxId } from "../../../config/func";
import { MessageListQueryDto, FavoriteResponse } from "../types/FavoriteTypes";

export const getFavoriteMessages = async (
  query: MessageListQueryDto
): Promise<FavoriteResponse> => {
  const isSearch =
    !!query.search || !!query.datestart || query.dateend || query.from;
  const url = isSearch ? "search" : "messages/favorite";

  // اضافه کردن mailbox id از localStorage
  const mailboxId = getMailboxId("FAVORITE");
  const queryWithMailbox = {
    ...query,
    mailbox: mailboxId,
  };

  const { data } = await axios.get(`/email/${url}`, {
    params: queryWithMailbox,
  });
  return data;
};

// Note: moveMessageToFavorite and unfavoriteMessage are now handled by EmailActionsService
