import { SyncManager } from '@/lib/sync-manager'; import type { AutomationRule } from '@/types/automation-rule'; import type { UUID } from '@/types/uuid'; class AutomationRuleSyncService { private syncManager: SyncManager; constructor() { this.syncManager = new SyncManager({ storeName: 'automation_rules', endpoint: '/api/sync/automation-rules', }); } async sync() { return await this.syncManager.sync(); } async getAll(): Promise { const rules = await this.syncManager.getAll(); return rules.map((rule) => ({ ...rule, rules_json: typeof rule.rules_json === 'string' ? JSON.parse(rule.rules_json) : rule.rules_json, })); } async getById(id: UUID): Promise { const rule = await this.syncManager.getById(id); if (!rule) { return null; } return { ...rule, rules_json: typeof rule.rules_json === 'string' ? JSON.parse(rule.rules_json) : rule.rules_json, }; } async create(data: Omit): Promise { return await this.syncManager.createLocal( data as Omit & { id?: UUID; created_at?: string; updated_at?: string; }, ); } async update(id: UUID, data: Partial): Promise { await this.syncManager.updateLocal(id, data); } async delete(id: UUID): Promise { await this.syncManager.deleteLocal(id); } async getLastSyncTime(): Promise { return await this.syncManager.getLastSyncTime(); } isSyncing(): boolean { return this.syncManager.isSyncing(); } } export const automationRuleSyncService = new AutomationRuleSyncService();