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

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

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

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

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