import 'package:shared_preferences/shared_preferences.dart';

class LikeService {
  static const String _likesKey = 'liked_heroes';

  Future<void> likeHero(int heroId) async {
    final prefs = await SharedPreferences.getInstance();
    final likes = prefs.getStringList(_likesKey) ?? [];
    if (!likes.contains(heroId.toString())) {
      likes.add(heroId.toString());
      await prefs.setStringList(_likesKey, likes);
    }
  }

  Future<void> unlikeHero(int heroId) async {
    final prefs = await SharedPreferences.getInstance();
    final likes = prefs.getStringList(_likesKey) ?? [];
    likes.remove(heroId.toString());
    await prefs.setStringList(_likesKey, likes);
  }

  Future<bool> isHeroLiked(int heroId) async {
    final prefs = await SharedPreferences.getInstance();
    final likes = prefs.getStringList(_likesKey) ?? [];
    return likes.contains(heroId.toString());
  }
}
