import { create } from 'zustand';
import { apis } from '@/apis';

interface ChatState {
    QuestionList: string[];
}

interface ChatActions {
    setQuestionList: (list: string[]) => void;
}

export type ChatStore = ChatState & ChatActions & {
    fetchPresetsApi: (appId: string) => Promise<void>;
};

export const useChatStore = create<ChatStore>((set, get) => ({
    QuestionList: [],
    
    setQuestionList: (list) => set({ QuestionList: list }),
    
    fetchPresetsApi: async (appId: string) => {
        try {
            const res = await apis.getPresets(appId);
            if (res && Array.isArray(res)) {
                set({ QuestionList: res });
            }
        } catch (error) {
            console.error('Failed to fetch presets:', error);
        }
    },
}));

export default useChatStore;
