import type { PollResponse } from "~/server/models/poll-response"
export const usePollResponseStore = defineStore('usePollResponseStore', () => {
    const currentPollResponse = shallowReactive<PollResponse>({})
    const currentPollResponses = shallowRef<PollResponse[]>([])
    const create = async (pollResponse: any) => {

        try {
            const { data } = await useFetch<any>(`/api/services/poll-response`, {
                method: 'POST',
                body: pollResponse
            })
            data.value && (Object.assign(currentPollResponse, data.value))
            return currentPollResponse
        } catch (error) {

        }

    }

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

            data.value && (currentPollResponses.value = data.value)
            return currentPollResponses.value
        } catch (error) { }


    }

    return { currentPollResponse, currentPollResponses, create, fetchByPollId }
})

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