import type { Database } from '~/types/database.types' import { defineStore } from 'pinia' import { ref } from 'vue' type App = Database['public']['Tables']['apps']['Row'] type Bundle = Database['public']['Tables']['app_versions']['Row'] type Channel = Database['public']['Tables']['channels']['Row'] type Device = Database['public']['Tables']['devices']['Row'] export const useAppDetailStore = defineStore('appDetail', () => { // Current app data const currentApp = ref(null) const currentAppId = ref('') // Current bundle data const currentBundle = ref(null) const currentBundleId = ref(null) // Current channel data const currentChannel = ref(null) const currentChannelId = ref(null) // Current device data const currentDevice = ref(null) const currentDeviceId = ref('') function setApp(appId: string, app: App | null) { currentAppId.value = appId currentApp.value = app } function setBundle(bundleId: number, bundle: Bundle | null) { currentBundleId.value = bundleId currentBundle.value = bundle } function setChannel(channelId: number, channel: Channel | null) { currentChannelId.value = channelId currentChannel.value = channel } function setDevice(deviceId: string, device: Device | null) { currentDeviceId.value = deviceId currentDevice.value = device } function clearApp() { currentApp.value = null currentAppId.value = '' } function clearBundle() { currentBundle.value = null currentBundleId.value = null } function clearChannel() { currentChannel.value = null currentChannelId.value = null } function clearDevice() { currentDevice.value = null currentDeviceId.value = '' } function clearAll() { clearApp() clearBundle() clearChannel() clearDevice() } return { // App currentApp, currentAppId, setApp, clearApp, // Bundle currentBundle, currentBundleId, setBundle, clearBundle, // Channel currentChannel, currentChannelId, setChannel, clearChannel, // Device currentDevice, currentDeviceId, setDevice, clearDevice, // Clear all clearAll, } })