import { serverFetchJson } from "@/app/utils/fetchUtil";
import { BASE_API_URL } from "@/config/api";
import { cache } from "react";
import "server-only";

export interface Records {
    records: UserGroupResult[]
}

export interface UserGroupResult {
    id: number;
    action: () => void;
    name: string;
    description: string;
}

export type IndivUserGroup = {
  authIds: number[];
  data: any;
  userIds: number[];
}

export const fetchGroup = cache(async () => {
    return serverFetchJson<Records>(`${BASE_API_URL}/group`, {
      next: { tags: ["group"] },
    });
  });


export const fetchIndivGroup = cache(async (id: number) => {
    return serverFetchJson<IndivUserGroup>(`${BASE_API_URL}/group/${id}`, {
      next: { tags: ["group"] },
    });
  });
