import 'package:cheminova/models/user_model.dart';
import 'package:cheminova/services/api_service.dart';
import 'package:get/get.dart';

class HomeController extends GetxController {
  final ApiService _apiService = ApiService();
  final Rx<UserProfile?> userProfile = Rx<UserProfile?>(null);
  final RxBool isLoading = false.obs;
  final RxString error = ''.obs;

  @override
  void onInit() {
    super.onInit();
    fetchUserProfile();
  }

  Future<void> fetchUserProfile() async {
    // isLoading.value = true;
    error.value = '';

    // try {
      final response = await _apiService.get('/api/rd-get-me');

      if (response.statusCode == 200) {
        userProfile.value = UserProfile.fromJson(response.data);
      } else {
        error.value =
            'Failed to load user profile. Status code: ${response.statusCode}';
      }
    // } catch (e) {
    //   error.value = 'An error occurred: $e';
    // } finally {
    //   isLoading.value = false;
    // }
  }
}
