class SessionManager {
  // Private constructor
  SessionManager._internal();

  // Singleton instance
  static final SessionManager instance = SessionManager._internal();

  String? _cookie;
  Map<String, dynamic>? _currentUser;

  // Getter for the current user data
  Map<String, dynamic>? get currentUser => _currentUser;

  /// Starts a session by storing user data.
  void startSession(Map<String, dynamic> userData) {
    _currentUser = userData;
  }

  /// Saves the session cookie.
  void setCookie(String? cookie) {
    if (cookie != null) {
      // Extract only the essential part of the cookie to avoid extra attributes
      _cookie = cookie.split(';').first;
    }
  }

  /// Retrieves the saved session cookie.
  String? getCookie() {
    return _cookie;
  }

  /// Clears all session data.
  void clearSession() {
    _cookie = null;
    _currentUser = null;
  }
}
