import type { Db } from '@zync/db/queries'
import type { DeliverableNotification, Env } from '@zync/types'
import {
  createNotificationDedupStore,
  createNotificationPreferenceStore,
  deliverPlatformNotification,
} from '../../../../../packages/notifications/src/platform'

export function createPlatformNotificationDeps(
  db: Db,
  env: Pick<Env, 'INTEGRATION_ENCRYPTION_KEY' | 'VAPID_PRIVATE_KEY' | 'VAPID_PUBLIC_KEY'>,
  tenantId: string,
) {
  return {
    dedup: createNotificationDedupStore(db),
    preferences: createNotificationPreferenceStore(db, tenantId),
    deliver(userId: string, notification: DeliverableNotification) {
      return deliverPlatformNotification(userId, notification, db, env, tenantId, {
        dedup: this.dedup,
        preferences: this.preferences,
      })
    },
  }
}
