import { cpanelFetch } from "@/lib/utils";
import { api3BaseCommand } from "../..";
import { MimeDeleteRedirectProps } from "../../types";

export default async function DeleteRedirect(
  props: MimeDeleteRedirectProps
): Promise<any> {
  const command = api3BaseCommand({
    command: "Mime",
    subcommand: "delete_redirect",
  });

  const params: { [key: string]: any } = props;

  const paramsString = Object.keys(params)
    .filter((e) => e !== undefined)
    .map((e) => `${e}=${params[e]}`)
    .join("&");

  const fetchString = `${command}${paramsString}`;

  const response = await cpanelFetch(fetchString);

  if (!response.ok) {
    throw new Error();
  }

  return await response.json();
}
