import PouchDB from '@/api/PouchDB' import type { BaseDocument, QRCodeDocument, ChatDocument, MessageDocument, WebPushSubscriptionDocument, PublicSettingsDocument, UserChatSettingsDocument, } from '@hereconnect/types' import { DB_NAMES } from '@/constants/dbNames' export const getRemoteDb = (dbName: DB_NAMES) => new PouchDB(new URL(`${import.meta.env.VITE_API_URL}/${dbName}`, location.origin).toString(), { skip_setup: true, }) export const getLocalDb = (dbName: DB_NAMES) => new PouchDB(dbName) export const qrCodeDbRemote = getRemoteDb(DB_NAMES.QR) export const qrCodeDbLocal = getLocalDb(DB_NAMES.QR) export const messagesDbLocal = getLocalDb(DB_NAMES.MESSAGES) export const chatsDbLocal = getLocalDb(DB_NAMES.CHATS) export const chatsDbRemote = getRemoteDb(DB_NAMES.CHATS) export const webPushSubscriptionsDbRemote = getRemoteDb< WebPushSubscriptionDocument >(DB_NAMES.WEB_PUSH_SUBSCRIPTIONS) export const publicSettingsDbRemote = getRemoteDb(DB_NAMES.PUBLIC_SETTINGS) export const messagesDbRemote = getRemoteDb(DB_NAMES.MESSAGES) export const userChatSettingsDbRemote = getRemoteDb( DB_NAMES.USER_CHAT_SETTINGS, )