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

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

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

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

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

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

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

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

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

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

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

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

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

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