import 'package:hive_flutter/hive_flutter.dart'; /// Kullanılan promptların global geçmişi — autocomplete için. class PromptGecmisi { static Box? _kutu; static const _maxKayit = 100; static Future _box() async => _kutu ??= await Hive.openBox('promptlar'); static Future> liste() async { final b = await _box(); return b.values.cast().toList().reversed.toList(); } static Future ekle(String prompt) async { if (prompt.trim().isEmpty || prompt.length < 4) return; final b = await _box(); // Dedup: aynı prompt varsa eskisini sil, en sona ekle final mevcut = b.values.cast().toList(); if (mevcut.contains(prompt)) { final yenidenSira = [...mevcut.where((p) => p != prompt), prompt]; await b.clear(); for (final p in yenidenSira) { await b.add(p); } } else { await b.add(prompt); } while (b.length > _maxKayit) { await b.deleteAt(0); } } static Future sil(String prompt) async { final b = await _box(); final keys = b.keys.toList(); for (final k in keys) { if (b.get(k) == prompt) { await b.delete(k); } } } static Future> ara(String parca) async { if (parca.trim().isEmpty) return await liste(); final hepsi = await liste(); final kucuk = parca.toLowerCase(); return hepsi.where((p) => p.toLowerCase().contains(kucuk)).toList(); } }