import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getScreens, bindScreenRoom } from '../api/screens'

export const useScreensStore = defineStore('screens', () => {
  const list = ref([])

  async function fetchScreens() {
    const res = await getScreens()
    list.value = res.data ?? []
    return list.value
  }

  async function bindRoom(screenId, roomId) {
    const res = await bindScreenRoom(screenId, roomId)
    await fetchScreens()
    return res
  }

  return {
    list,
    fetchScreens,
    bindRoom,
  }
})
