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

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

  Future<dynamic> getEntities() async {
    try {
      final response =
          await _helper.getGetApiResponse('$baseUrl/Ad7/Ad7');
      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/Ad7/Ad7/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/Ad7/Ad7', 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/Ad7/Ad7/$entityId', entity);
      print(entity);
    } catch (e) {
      throw Exception('Failed to update entity: $e');
    }
  }

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


 Future<dynamic> insertsupport(Map<String, dynamic> entity) async {
    try {
      String apiUrl = "$baseUrl/Support/Support_insert";
      final response = await _helper.getPostApiResponse(apiUrl,entity);
      return response;
    } catch (e) {
      throw Exception('Failed to Insert: $e');
    }
  }

}
