import 'package:shared_models/models/translation_request.dart';
import 'package:shared_models/models/user.dart';

class MemoryStore {
  static final Map<String, TranslationRequest> _googooTranslations = {};
  static final Map<String, TranslationRequest> _humanTranslations = {};
  static final Map<String, User> _users = {};

  // User methods
  static User? getUser(String userId) => _users[userId];
  static void addUser(User user) => _users[user.id] = user;

  // Googoo translation methods
  static TranslationRequest? getGoogooTranslation(String id, String userId) {
    final translation = _googooTranslations[id];
    if (translation?.userId != userId) return null;
    return translation;
  }

  static void addGoogooTranslation(TranslationRequest translation) {
    _googooTranslations[translation.id] = translation;
  }

  static List<TranslationRequest> getUserGoogooTranslations(String userId) {
    return _googooTranslations.values.where((t) => t.userId == userId).toList();
  }

  // Human translation methods
  static TranslationRequest? getHumanTranslation(String id, String userId) {
    final translation = _humanTranslations[id];
    if (translation?.userId != userId) return null;
    return translation;
  }

  static void addHumanTranslation(TranslationRequest translation) {
    _humanTranslations[translation.id] = translation;
  }

  static List<TranslationRequest> getUserHumanTranslations(String userId) {
    return _humanTranslations.values.where((t) => t.userId == userId).toList();
  }

  // Cleanup methods
  static void removeOldTranslations(Duration maxAge) {
    final cutoffTime = DateTime.now().subtract(maxAge);
    _googooTranslations.removeWhere(
      (_, translation) => translation.timestamp.isBefore(cutoffTime),
    );
    _humanTranslations.removeWhere(
      (_, translation) => translation.timestamp.isBefore(cutoffTime),
    );
  }

  // For testing/development
  static void clearAll() {
    _googooTranslations.clear();
    _humanTranslations.clear();
    _users.clear();
  }
}
