import 'dart:async';

import 'package:shared_preferences/shared_preferences.dart';

class SharedPrefManager {
  static String USER_ID = "user.id";
  static String USER_TOKEN = "user.token";
  static String USER_NAME = "user.name";
  static String PASSWORD = "user.password";
  static String REFRESH_TOKEN = "user.refresh.token";
  static String DATA = "data";

  static Future<SharedPreferences> _prefs = SharedPreferences.getInstance();

  static setUserId(String cookie) async {
    final prefs = await SharedPreferences.getInstance();
    prefs.setString(USER_ID, cookie) ?? "NA";
  }

  static Future<String> getUserId() async {
    SharedPreferences prefs = await _prefs;
    return prefs.getString(USER_ID) ?? "";
  }

  static setUserToken(String cookie) async {
    final prefs = await SharedPreferences.getInstance();
    prefs.setString(USER_TOKEN, cookie) ?? "NA";
  }

  static Future<String> getUserToken() async {
    SharedPreferences prefs = await _prefs;
    return prefs.getString(USER_TOKEN) ?? "";
  }

  static setPhoneOrEmail(String cookie) async {
    final prefs = await SharedPreferences.getInstance();
    prefs.setString(USER_NAME, cookie) ?? "NA";
  }

  static Future<String> getPhoneOrEmail() async {
    SharedPreferences prefs = await _prefs;
    return prefs.getString(USER_NAME) ?? "";
  }

  static setUserPassword(String cookie) async {
    final prefs = await SharedPreferences.getInstance();
    prefs.setString(PASSWORD, cookie) ?? "NA";
  }

  static Future<String> getUserPassword() async {
    SharedPreferences prefs = await _prefs;
    return prefs.getString(PASSWORD) ?? "";
  }

  static setRefreshToken(String cookie) async {
    final prefs = await SharedPreferences.getInstance();
    prefs.setString(REFRESH_TOKEN, cookie) ?? "NA";
  }

  static Future<String> getRefreshToken() async {
    SharedPreferences prefs = await _prefs;
    return prefs.getString(REFRESH_TOKEN) ?? "";
  }

  static setData(String cookie) async {
    final prefs = await SharedPreferences.getInstance();
    prefs.setString(DATA, cookie) ?? "NA";
  }

  static Future<String> getData() async {
    SharedPreferences prefs = await _prefs;
    return prefs.getString(DATA) ?? "";
  }
}
