import 'package:shared_preferences/shared_preferences.dart';

class PrefService{

  Future createCacheidUsuario(String idUsuario)async{

    SharedPreferences _preferences = await SharedPreferences.getInstance();
    _preferences.setString('idUsuario', idUsuario);
  }
  Future createCacheUnidade(String idUnidade, String nomeUnidade)async{

    SharedPreferences _preferences = await SharedPreferences.getInstance();
    _preferences.setString('idUnidade', idUnidade);
    _preferences.setString('nomeUnidade', nomeUnidade);
  }
  Future createCacheSync(String area,bool foraArea)async{

    SharedPreferences _preferences = await SharedPreferences.getInstance();
    _preferences.setString('area', area);
    _preferences.setBool('foraArea', foraArea);
  }

  Future createCacheModel(String user,String password,String city,String mode)async{

    SharedPreferences _preferences = await SharedPreferences.getInstance();
    _preferences.setString('user', user);
    _preferences.setString('password', password);
    _preferences.setString('city', city);
    _preferences.setString('mode', mode);
  }

  Future readCacheIdUsuario(String idUsuario) async{
    SharedPreferences _preferences = await SharedPreferences.getInstance();
    var idUsuario = _preferences.getString('idUsuario');
    return idUsuario;
  }
  Future readCacheUnidade(String idUnidade) async{
    SharedPreferences _preferences = await SharedPreferences.getInstance();
    var idUnidade = _preferences.getString('idUnidade');
    var nomeUnidade = _preferences.getString('nomeUnidade');
    List list =[
      idUnidade,
      nomeUnidade,
    ];
    return list;
  }
  Future readCacheModel(String user,String password,String city,String mode) async{
    SharedPreferences _preferences = await SharedPreferences.getInstance();
    String? user = _preferences.getString('user');
    String? password = _preferences.getString('password');
    String? city = _preferences.getString('city');
    String? mode = _preferences.getString('mode');
    List list =[
      user,
      password,
      city,
      mode
    ];
    return list;
  }
  Future readCacheSync(String area,bool foraArea) async{
    SharedPreferences _preferences = await SharedPreferences.getInstance();
    String? area = _preferences.getString('area');
    bool? foraArea = _preferences.getBool('foraArea');
    List list =[
      area,
      foraArea
    ];
    return list;
  }

  Future removeCache(String idUsuario) async{
    SharedPreferences _preferences = await SharedPreferences.getInstance();
    _preferences.remove('idUsuario');
  }
}