import axios from "../config/axios";
import { BulkActionRequest } from "../pages/received/types/Types";

export const bulkAction = async (request: BulkActionRequest) => {
  const { data } = await axios.post(
    `/email/messages/bulk-action?mailbox=${request.mailbox}`,
    request
  );
  return data;
};

export const markMessageAsSeen = async (messageId: number, mailbox: string) => {
  const { data } = await axios.patch(
    `/email/messages/${messageId}/seen?mailbox=${mailbox}`
  );
  return data;
};

export const moveMessageToArchive = async (
  messageId: number,
  mailbox: string
) => {
  const { data } = await axios.patch(
    `/email/messages/${messageId}/archive?mailbox=${mailbox}`
  );
  return data;
};

export const moveMessageToFavorite = async (
  messageId: number,
  mailbox: string
) => {
  const { data } = await axios.patch(
    `/email/messages/${messageId}/favorite?mailbox=${mailbox}`
  );
  return data;
};

export const moveMessageToTrash = async (
  messageId: number,
  mailbox: string
) => {
  const { data } = await axios.patch(
    `/email/messages/${messageId}/trash?mailbox=${mailbox}`
  );
  return data;
};

export const deleteMessagePermanently = async (
  messageId: number,
  mailbox: string
) => {
  const { data } = await axios.delete(
    `/email/messages/${messageId}?mailbox=${mailbox}`
  );
  return data;
};

export const sendEmail = async (messageId: number) => {
  const { data } = await axios.post(`/email/send?messageId=${messageId}`);
  return data;
};

export const updateDraft = async (messageId: number, draftData: unknown) => {
  const { data } = await axios.patch(
    `/email/messages/drafts/${messageId}`,
    draftData
  );
  return data;
};

export const deleteDraft = async (messageId: number, mailbox: string) => {
  const { data } = await axios.delete(
    `/email/messages/drafts/${messageId}?mailbox=${mailbox}`
  );
  return data;
};

export const sendDraft = async (messageId: number) => {
  const { data } = await axios.post(`/email/messages/drafts/${messageId}/send`);
  return data;
};

export const unfavoriteMessage = async (messageId: number, mailbox: string) => {
  const { data } = await axios.patch(
    `/email/messages/${messageId}/unfavorite?mailbox=${mailbox}`
  );
  return data;
};

export const unarchiveMessage = async (messageId: number, mailbox: string) => {
  const { data } = await axios.patch(
    `/email/messages/${messageId}/unarchive?mailbox=${mailbox}`
  );
  return data;
};

export const restoreMessage = async (messageId: number, mailbox: string) => {
  const { data } = await axios.patch(
    `/email/messages/${messageId}/restore?mailbox=${mailbox}`
  );
  return data;
};
