import CottonKit import Foundation @testable import CottonUI /// Local preference injection belongs to fixtures. The shipping constructor /// requires a source, and RootView supplies the core's native preferences. @MainActor extension NotificationsModel { convenience init( core: any CottonCalling, centre: any ReminderCentre = SystemReminderCentre(), authority: any NotificationAuthority = SystemNotificationAuthority(), prefsStore: any NotificationPrefsStore = InMemoryNotificationPrefsStore(), facts: any DeviceFactsSource = SystemDeviceFacts(), bridge: NotificationBridge = .shared, settle: Duration = .milliseconds(600), timeZone: @escaping @Sendable () -> String = { TimeZone.current.identifier }, now: @escaping @Sendable () -> Date = { Date() }, databases: @escaping @MainActor () -> [String]? = { [] }, delivered: @escaping @Sendable () async -> [PushReceipt] = { [] } ) { self.init(core: core, centre: centre, authority: authority, preferences: StoredNotificationPreferences(store: prefsStore), initialPrefs: prefsStore.read(), facts: facts, bridge: bridge, settle: settle, timeZone: timeZone, now: now, databases: databases, delivered: delivered) } } private struct StoredNotificationPreferences: NotificationPreferenceSource { let store: any NotificationPrefsStore func read() async throws -> NotificationPrefs { store.read() } func markAsked(at stamp: String) async throws { var prefs = store.read() prefs.askedAt = stamp store.write(prefs) } }