"use server";

import { executeREST } from "app/_lib/zammad";

export const getGroupsAction = async () => {
  try {
    const groups = await executeREST({
      path: "/api/v1/groups",
    });
    const allGroups = groups ?? [];
    const formattedGroups = allGroups.map((group: any) => ({
      label: group.name,
      value: `gid://zammad/Group/${group.id}`,
    }));

    return formattedGroups;
  } catch (e) {
    console.error(e.message);
    return [];
  }
};
