import { apiFetch } from "./config";

export const loginManage = async (domain, password, email = "") => {
  return await apiFetch("/manage/api/login", {
    method: "POST",
    body: JSON.stringify({ domain, password, email }),
  });
};

export const getDomainInfo = async (domain, password, email = "") => {
  return await apiFetch("/manage/api/domain-info", {
    method: "POST",
    body: JSON.stringify({ domain, password, email }),
  });
};

export const createUser = async (domain, owner_pass, local_part, name, password, quota_mb = 1024) => {
  return await apiFetch("/manage/api/create-user", {
    method: "POST",
    body: JSON.stringify({
      domain,
      owner_pass,
      local_part,
      name,
      password,
      quota: quota_mb,
    }),
  });
};

export const deleteUser = async (domain, owner_pass, email) => {
  return await apiFetch("/manage/api/delete-user", {
    method: "POST",
    body: JSON.stringify({ domain, owner_pass, email }),
  });
};

export const changeUserPassword = async (domain, owner_pass, email, new_password) => {
  return await apiFetch("/manage/api/change-password", {
    method: "POST",
    body: JSON.stringify({ domain, owner_pass, email, new_password }),
  });
};

export const toggleUserActive = async (domain, owner_pass, email, active) => {
  return await apiFetch("/manage/api/toggle-active", {
    method: "POST",
    body: JSON.stringify({ domain, owner_pass, email, active }),
  });
};

export const getAliases = async (domain, owner_pass) => {
  return await apiFetch("/manage/api/aliases", {
    method: "POST",
    body: JSON.stringify({ domain, owner_pass }),
  });
};

export const addAlias = async (domain, owner_pass, address, goto_address) => {
  return await apiFetch("/manage/api/add-alias", {
    method: "POST",
    body: JSON.stringify({ domain, owner_pass, address, goto: goto_address }),
  });
};

export const deleteAlias = async (domain, owner_pass, address, goto_address) => {
  return await apiFetch("/manage/api/delete-alias", {
    method: "POST",
    body: JSON.stringify({ domain, owner_pass, address, goto: goto_address }),
  });
};

export const checkLiveDns = async (domain) => {
  return await apiFetch("/api/check-live-dns", {
    method: "POST",
    body: JSON.stringify({ domain }),
  });
};
