import 'package:get/get.dart';
import 'package:dio/dio.dart';
import '../../../core/network/dio_client.dart';
import '../../../core/utils/app_snackbar.dart';
import '../../../core/utils/logger.dart';

class TenantsManagementController extends GetxController {
  final Dio _dio = DioClient().client;

  var isLoading = true.obs;
  var tenants = <Map<String, dynamic>>[].obs;

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

  Future<void> fetchTenants() async {
    try {
      isLoading.value = true;
      final response = await _dio.get('tenants');
      if (response.data['success'] == true) {
        tenants.value = List<Map<String, dynamic>>.from(response.data['data']);
      }
    } catch (e) {
      AppLogger.error('Failed to fetch tenants', e);
      AppSnackbar.showError('خطأ', 'تعذر تحميل المكاتب المحاسبية');
    } finally {
      isLoading.value = false;
    }
  }
}
