import { IStore } from '../IStore';

/**
 * AuditStore - IndexedDB store configuration for audit entries
 *
 * Stores all entity changes for:
 * - Compliance and audit trail
 * - Sync tracking with backend
 * - Change history
 *
 * Indexes:
 * - syncStatus: For finding pending entries to sync
 * - synced: Boolean flag for quick sync queries
 * - entityId: For getting all audits for a specific entity
 * - timestamp: For chronological queries
 */
export class AuditStore implements IStore {
  readonly storeName = 'audit';

  create(db: IDBDatabase): void {
    const store = db.createObjectStore(this.storeName, { keyPath: 'id' });
    store.createIndex('syncStatus', 'syncStatus', { unique: false });
    store.createIndex('synced', 'synced', { unique: false });
    store.createIndex('entityId', 'entityId', { unique: false });
    store.createIndex('timestamp', 'timestamp', { unique: false });
  }
}
