import { useContext } from "react";
import NimChatContext from ".";
import ConversationContext from "./ConversationContext";
import NimMsgContext from "./NimMsgContext";
import NimUserContext from "./NimUserContext";

export const useNimChat = () => {
  const context = useContext(NimChatContext);
  if (!context) {
    throw new Error("useNimChat must be used within a NimChatProvider");
  }
  return context;
}

export const useNimConversation = () => {
  const context = useContext(ConversationContext);
  if (!context) {
    throw new Error("useNimConversation must be used within a ConversationProvider");
  }
  return context;
}

export const useNimMsgContext = () => {
  const context = useContext(NimMsgContext);
  if (!context) {
    throw new Error("useNimMsgContext must be used within a NimMsgContextProvider");
  }
  return context;
}

// 导出便捷的 hook
export const useNimLoginStatus = () => {
  const { isNimLoggedIn, nimLoginStatus } = useNimChat();
  return { isNimLoggedIn, nimLoginStatus };
}


export const useNimUser = () => {
  const context = useContext(NimUserContext);
  if (!context) {
    throw new Error("useNimUser must be used within a NimUserProvider");
  }
  return context;
}