import { IStore } from '../IStore'; /** * EventStore - IndexedDB ObjectStore definition for calendar events * * Defines schema, indexes, and store creation logic. * Part of modular storage architecture where each entity has its own folder. */ export class EventStore implements IStore { /** ObjectStore name in IndexedDB (static for backward compatibility) */ static readonly STORE_NAME = 'events'; /** ObjectStore name in IndexedDB (instance property for IStore interface) */ readonly storeName = EventStore.STORE_NAME; /** * Create the events ObjectStore with indexes * Called during database upgrade (onupgradeneeded) * * @param db - IDBDatabase instance */ create(db: IDBDatabase): void { // Create ObjectStore with 'id' as keyPath const store = db.createObjectStore(EventStore.STORE_NAME, { keyPath: 'id' }); // Index: start (for date range queries) store.createIndex('start', 'start', { unique: false }); // Index: end (for date range queries) store.createIndex('end', 'end', { unique: false }); // Index: syncStatus (for filtering by sync state) store.createIndex('syncStatus', 'syncStatus', { unique: false }); // Index: resourceId (CRITICAL for resource-mode filtering) store.createIndex('resourceId', 'resourceId', { unique: false }); // Index: customerId (for customer-centric queries) store.createIndex('customerId', 'customerId', { unique: false }); // Index: bookingId (for event-to-booking lookups) store.createIndex('bookingId', 'bookingId', { unique: false }); // Compound index: startEnd (for optimized range queries) store.createIndex('startEnd', ['start', 'end'], { unique: false }); } }