import type { Poll } from "~/server/models/poll"
export const usePollStore = defineStore('usePollStore', () => {
    const currentPoll = shallowReactive<Poll>({})
    async function fetchById(id: string) {

        try {
            const { data } = await useFetch<any>(`/api/services/poll-by-id`, {
                query: {
                    pollId: id
                }
            })

            data.value && (Object.assign(currentPoll, data.value))
            return currentPoll
        } catch(error) {

        }
    }

    async function categoryId() {
        try {
            const { data } = await useFetch(`/api/services/category-tree`)
            return data.value
        } catch (error) {}
    
    }

    return { fetchById, currentPoll, categoryId }
})

if(import.meta.hot) {
    import.meta.hot.accept(acceptHMRUpdate(usePollStore, import.meta.hot))
}