import '../../../../data/network/base_network_service.dart';
import '../../../../data/network/network_api_service.dart';
import '../../../../resources/api_constants.dart';

class TestfRepoScreen {
  final String baseUrl = ApiConstants.baseUrl;
  final BaseNetworkService _helper = NetworkApiService();

  Future<dynamic> getEntities() async {
    try {
      final response =
          await _helper.getGetApiResponse('$baseUrl/Testf/Testf');
      return response;
    } catch (e) {
      throw Exception('Failed to get all entities: $e');
    }
  }

  Future<dynamic> getAllWithPagination(int page, int size) async {
    try {
      final response = await _helper.getGetApiResponse(
          '$baseUrl/Testf/Testf/getall/page?page=$page&size=$size');
      return response;
    } catch (e) {
      throw Exception('Failed to get all without pagination: $e');
    }
  }

  Future<dynamic> createEntity(Map<String, dynamic> entity) async {
    try {
      print("in post api$entity");
      final response = await _helper.getPostApiResponse(
          '$baseUrl/Testf/Testf', entity);

      print(entity);

      return response;
    } catch (e) {
      throw Exception('Failed to create entity: $e');
    }
  }

  Future<void> updateEntity(int entityId, Map<String, dynamic> entity) async {
    try {
      await _helper.getPutApiResponse(
          '$baseUrl/Testf/Testf/$entityId', entity);
      print(entity);
    } catch (e) {
      throw Exception('Failed to update entity: $e');
    }
  }

  Future<void> deleteEntity(int entityId) async {
    try {
      await _helper
          .getDeleteApiResponse('$baseUrl/Testf/Testf/$entityId');
    } catch (e) {
      throw Exception('Failed to delete entity: $e');
    }
  }
}
