import { api } from "@/config";
import { UID } from "@/constants";
import { getStorageItem } from "@/utils/storage";

export async function queryUserGroup() {
  const user_id = await getStorageItem(UID);
  return api.get<Model.GroupResponse>(`/api/members/${user_id}/groups`);
}

export async function queryChilrentOfGroups(
  group_id: string,
  level: number = 5,
  isTree: boolean = false
) {
  // ensure proper query param values when not provided by caller
  const lvl = typeof level === "number" ? level : 5;
  const tree = !!isTree;
  const params = {
    level: lvl,
    tree: tree,
  };
  return api.get<Model.GroupResponse>(`/api/groups/${group_id}/children`, {
    params,
  });
}
