import { MailboxEnum } from "@/pages/received/enum/Enum";
import axios from "../../../config/axios";
import { getMailboxId } from "../../../config/func";
import { MessageListQueryDto, TrashResponse } from "../types/TrashTypes";

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

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

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

// Note: deleteMessagePermanently and restoreMessage are now handled by EmailActionsService

export const emptyTrash = async () => {
  const mailboxId = getMailboxId(MailboxEnum.TRASH);
  const { data } = await axios.patch(
    `/email/messages/empty-trash?mailbox=${mailboxId}`
  );
  return data;
};
