import 'package:get/get.dart';
import 'package:sigap/src/cores/services/supabase_service.dart';
import 'package:sigap/src/utils/exceptions/exceptions.dart';

class CrimesRepository extends GetxController {
  static CrimesRepository get instance => Get.find();

  final _supabase = SupabaseService.instance.client;

  Future<List<Map<String, dynamic>>> getCrimeCategories() async {
    try {
      final response = await _supabase
          .from('crime_categories')
          .select('*')
          .order('name', ascending: true);

      return List<Map<String, dynamic>>.from(response);
    } catch (e) {
      throw TExceptions('Failed to fetch crime categories: ${e.toString()}');
    }
  }

  Future<Map<String, dynamic>> getCrimeCategoryById(String id) async {
    try {
      final response =
          await _supabase
              .from('crime_categories')
              .select('*')
              .eq('id', id)
              .single();

      return response;
    } catch (e) {
      throw TExceptions('Failed to fetch crime category: ${e.toString()}');
    }
  }
}
