import { defineStore } from 'pinia' import { ref } from 'vue' import { api } from '@/services/api' export interface Topic { id: string name: string description: string category: string } export interface SourceReference { type?: 'TEXT' | 'FIGURE' refLabel?: string bookId: string | null bookTitle: string page: number | null chunkText?: string figureId?: string label?: string caption?: string figureType?: string imageUrl?: string } export interface TopicSummary { id: string summaryNumber: number topicId: string topicName: string summary: string sources: SourceReference[] generatedAt: string } export interface SavedSummaryItem { id: string summaryNumber: number generatedAt: string } export const useTopicStore = defineStore('topics', () => { const topics = ref([]) const activeSummary = ref(null) const activeSummaryTopicId = ref(null) const summaryList = ref([]) const loading = ref(false) const summaryLoading = ref(false) const summaryListLoading = ref(false) const error = ref(null) async function fetchTopics() { loading.value = true error.value = null try { const response = await api.get('/topics') topics.value = response.data } catch (err: any) { error.value = err.message } finally { loading.value = false } } async function fetchSummaries(topicId: string) { summaryListLoading.value = true summaryList.value = [] error.value = null try { const response = await api.get(`/topics/${topicId}/summaries`) summaryList.value = response.data } catch (err: any) { error.value = err.message } finally { summaryListLoading.value = false } } async function fetchSummaryDetail(topicId: string, summaryId: string): Promise { summaryLoading.value = true activeSummary.value = null error.value = null try { const response = await api.get(`/topics/${topicId}/summaries/${summaryId}`) activeSummary.value = response.data return response.data } catch (err: any) { error.value = err.message return null } finally { summaryLoading.value = false } } async function generateSummary(topicId: string): Promise { summaryLoading.value = true activeSummaryTopicId.value = topicId activeSummary.value = null error.value = null try { const response = await api.post(`/topics/${topicId}/summary`) activeSummary.value = response.data return response.data } catch (err: any) { error.value = err.message return null } finally { summaryLoading.value = false activeSummaryTopicId.value = null } } return { topics, activeSummary, activeSummaryTopicId, summaryList, loading, summaryLoading, summaryListLoading, error, fetchTopics, fetchSummaries, fetchSummaryDetail, generateSummary } })