import { useQuery } from "@tanstack/react-query";

import { client } from "@/lib/rpc";
import { MemberRole } from "../types";

interface UseGetCurrentMemberProps {
  workspaceId: string;
}

interface CurrentMember {
  id: string;
  role: MemberRole;
  userId: string;
}

export const useGetCurrentMember = ({ workspaceId }: UseGetCurrentMemberProps) => {
  const query = useQuery<CurrentMember>({
    queryKey: ["current-member", workspaceId],
    queryFn: async () => {
      const response = await client.api.members.current.$get({
        query: { workspaceId },
      });

      if (!response.ok) {
        throw new Error("Failed to fetch current member");
      }

      const { data } = await response.json();
      return data;
    },
    enabled: !!workspaceId,
  });

  return query;
}; 