import 'package:shared_preferences/shared_preferences.dart';

class SharedPreferencesHelper {
  static late SharedPreferences preferences;

  static Future<void> initial() async {
    preferences = await SharedPreferences.getInstance();
  }

  static const String token = 'auth_token';
  static const String themeMode = 'theme-mode';
  static const String inviteLastTime = 'invite_last_time';
  static const String videoGuid = 'video-guid';
  static const String audioGuid = 'audio-guid';
  static const String imageGuid = 'image-guid';
  static const String onboardingSeen = 'onboarding-seen';
}

class AuthTokenStorage {
  static String getToken() {
    final prefs = SharedPreferencesHelper.preferences;
    return prefs.getString(SharedPreferencesHelper.token) ?? "";
  }

  static Future<void> setToken(String token) async {
    final prefs = SharedPreferencesHelper.preferences;
    await prefs.setString(SharedPreferencesHelper.token, token);
  }

  static void clearToken() {
    final prefs = SharedPreferencesHelper.preferences;
    prefs.remove(SharedPreferencesHelper.token);
  }
}

class ThemeModeStorage {
  static String getMode() {
    final prefs = SharedPreferencesHelper.preferences;
    return prefs.getString(SharedPreferencesHelper.themeMode) ?? "system";
  }

  static void setMode(String mode) {
    final prefs = SharedPreferencesHelper.preferences;
    prefs.setString(SharedPreferencesHelper.themeMode, mode);
  }

  static void clearMode() {
    final prefs = SharedPreferencesHelper.preferences;
    prefs.remove(SharedPreferencesHelper.themeMode);
  }
}

class OnBoardingStorage {
  static bool hasSeen() {
    final prefs = SharedPreferencesHelper.preferences;
    return prefs.getBool(SharedPreferencesHelper.onboardingSeen) ?? false;
  }

  static Future<void> setAsSeen() async {
    final prefs = SharedPreferencesHelper.preferences;
    await prefs.setBool(SharedPreferencesHelper.onboardingSeen, true);
  }
}

class InvitePopupStorage {
  static String getLastTime() {
    final prefs = SharedPreferencesHelper.preferences;
    return prefs.getString(SharedPreferencesHelper.inviteLastTime) ?? "";
  }

  static void setLastTime(String lastTimeIso) {
    final prefs = SharedPreferencesHelper.preferences;
    prefs.setString(SharedPreferencesHelper.inviteLastTime, lastTimeIso);
  }

  static void clearLastTime() {
    final prefs = SharedPreferencesHelper.preferences;
    prefs.remove(SharedPreferencesHelper.inviteLastTime);
  }
}

class GuidsStorage {
  static bool isSeenVideo() {
    final prefs = SharedPreferencesHelper.preferences;
    return prefs.getBool(SharedPreferencesHelper.videoGuid) ?? false;
  }

  static void setSeenVideo(bool seen) {
    final prefs = SharedPreferencesHelper.preferences;
    prefs.setBool(SharedPreferencesHelper.videoGuid, seen);
  }

  static void clearSeenVideo() {
    final prefs = SharedPreferencesHelper.preferences;
    prefs.remove(SharedPreferencesHelper.videoGuid);
  }

  static bool isSeenAudio() {
    final prefs = SharedPreferencesHelper.preferences;
    return prefs.getBool(SharedPreferencesHelper.audioGuid) ?? false;
  }

  static void setSeenAudio(bool seen) {
    final prefs = SharedPreferencesHelper.preferences;
    prefs.setBool(SharedPreferencesHelper.audioGuid, seen);
  }

  static void clearSeenAudio() {
    final prefs = SharedPreferencesHelper.preferences;
    prefs.remove(SharedPreferencesHelper.audioGuid);
  }

  static bool isSeenImage() {
    final prefs = SharedPreferencesHelper.preferences;
    return prefs.getBool(SharedPreferencesHelper.imageGuid) ?? false;
  }

  static void setSeenImage(bool seen) {
    final prefs = SharedPreferencesHelper.preferences;
    prefs.setBool(SharedPreferencesHelper.imageGuid, seen);
  }

  static void clearSeenImage() {
    final prefs = SharedPreferencesHelper.preferences;
    prefs.remove(SharedPreferencesHelper.imageGuid);
  }
}
