import { TwitterBookmark, ProcessedBookmark, BookmarkSyncStatus } from './bookmark-models'; export class BookmarkStorageService { private static readonly STORAGE_KEYS = { BOOKMARKS: 'twitter_bookmarks', PROCESSED_BOOKMARKS: 'processed_bookmarks', SYNC_STATUS: 'sync_status', }; static saveBookmarks(bookmarks: TwitterBookmark[]): void { if (typeof window === 'undefined') return; const existing = this.getBookmarks(); const newBookmarks = bookmarks.filter( (newBookmark) => !existing.some((existing) => existing.id === newBookmark.id) ); const allBookmarks = [...existing, ...newBookmarks]; localStorage.setItem(this.STORAGE_KEYS.BOOKMARKS, JSON.stringify(allBookmarks)); } static getBookmarks(): TwitterBookmark[] { if (typeof window === 'undefined') return []; const data = localStorage.getItem(this.STORAGE_KEYS.BOOKMARKS); return data ? JSON.parse(data) : []; } static getBookmarkById(id: string): TwitterBookmark | null { if (typeof window === 'undefined') return null; const bookmarks = this.getBookmarks(); return bookmarks.find((bookmark) => bookmark.id === id) || null; } static clearAll(): void { if (typeof window === 'undefined') return; localStorage.removeItem(this.STORAGE_KEYS.BOOKMARKS); localStorage.removeItem(this.STORAGE_KEYS.PROCESSED_BOOKMARKS); localStorage.removeItem(this.STORAGE_KEYS.SYNC_STATUS); } static exportBookmarks(): string { if (typeof window === 'undefined') return ''; const bookmarks = this.getBookmarks(); const data = { bookmarks, exportedAt: new Date().toISOString(), }; return JSON.stringify(data, null, 2); } static importBookmarks(jsonData: string): void { if (typeof window === 'undefined') return; try { const data = JSON.parse(jsonData); if (data.bookmarks) { localStorage.setItem(this.STORAGE_KEYS.BOOKMARKS, JSON.stringify(data.bookmarks)); } } catch (error) { throw new Error('Invalid bookmark data format'); } } }