// ignore_for_file: non_constant_identifier_names

import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';

class AuthService extends GetxService {
  static AuthService get to => Get.find();
  final box = GetStorage();

  /// Mocks a login process
  final _token = ''.obs;
  String get token => box.read('token') ?? _token.value;
  final isLoggedIn = false.obs;
  bool get isLoggedInValue => box.read('auth') ?? isLoggedIn.value;
  


  void login(newToken) {
    isLoggedIn.value = true;
    _token.value = newToken;
    box.write('auth', true);
    box.write('token', newToken);
  }

  void logout(String logoutURL) {
    isLoggedIn.value = false;
    box.write('auth', false);
    _token.value = '';
    box.write('token', '');

    Get.offAllNamed(logoutURL);
  }
}

final authService = Get.put(AuthService());