import type { MujianSdk } from '@mujian/js-sdk';
import type { PersonaInfo, ProjectInfo } from '@mujian/js-sdk/types';
import { create } from 'zustand';

type GlobalState = {
  projectInfo: ProjectInfo | null;
  activePersona: PersonaInfo | null;
  init: (mujian: MujianSdk) => Promise<void>;
};

export const useGlobalStore = create<GlobalState>((set) => ({
  count: 0,
  projectInfo: null,
  activePersona: null,

  init: async (mujian: MujianSdk) => {
    const [projectInfo, persona] = await Promise.all([
      mujian.ai.chat.project.getInfo(),
      mujian.ai.chat.settings.persona.getActive(),
    ]);
    set({ projectInfo, activePersona: persona });
  },
}));
