"use server";

import { revalidatePath } from "next/cache";
import { createTicketMutation } from "app/_graphql/createTicketMutation";
import { updateTicketMutation } from "app/_graphql/updateTicketMutation";
import { updateTagsMutation } from "app/_graphql/updateTagsMutation";
// import { executeMutation } from "app/_lib/graphql";
// import { AddAssetMutation } from "../_graphql/AddAssetMutation";

export const createTicketAction = async (
  currentState: any,
  formData: FormData,
) => {
  /*

    const createTicket = async () => {
    await fetcher({
      document: createTicketMutation,
      variables: {
        input: {
          ticket,
        },
      },
    });
    closeDialog();
    setBody("");
  };


  try {
    const ticket = {
      title: formData.get("title"),
    };

    const result = await executeMutation({
      project,
      mutation: AddAssetMutation,
      variables: {
        input: asset,
      },
    });

    revalidatePath(`/${project}/assets`);

    return {
      ...currentState,
      values: { ...asset, ...result.addAsset, project },
      success: true,
    };
  } catch (e: any) {
    return { success: false, message: e?.message ?? "Unknown error" };
  }
   */
};

export const updateTicketAction = async (
  currentState: any,
  formData: FormData,
) => {
  /*
  try {
    const { id, project } = currentState.values;
    const updatedTicket = {
      title: formData.get("title"),
    };
    await executeMutation({
      project,
      mutation: UpdateAssetMutation,
      variables: {
        id,
        input: updatedAsset,
      },
    });

    revalidatePath(`/${project}/assets/${id}`);

    return {
      ...currentState,
      values: { ...currentState.values, ...updatedAsset, id, project },
      success: true,
    };
  } catch (e: any) {
    return { success: false, message: e?.message ?? "Unknown error" };
  }
   */
};

export const updateTicketTagsAction = async (
  currentState: any,
  formData: FormData,
) => {
  /*
  try {
    const { id, project } = currentState.values;
    const updatedTicket = {
      title: formData.get("title"),
    };
    await executeMutation({
      project,
      mutation: UpdateAssetMutation,
      variables: {
        id,
        input: updatedAsset,
      },
    });

    revalidatePath(`/${project}/assets/${id}`);

    return {
      ...currentState,
      values: { ...currentState.values, ...updatedAsset, id, project },
      success: true,
    };
  } catch (e: any) {
    return { success: false, message: e?.message ?? "Unknown error" };
  }
   */
};
