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

class ad8ApiService {
  final String baseUrl = ApiConstants.baseUrl;

      final BaseNetworkService _helper = NetworkApiService();



   Future<List<Map<String, dynamic>>> getEntities() async {

    try {
      final response = await _helper.getGetApiResponse('$baseUrl/Ad8/Ad8');
      final entities = (response as List).cast<Map<String, dynamic>>();
      return entities;
    } catch (e) {
      throw Exception('Failed to get all entities: $e');
    }
  }
Future<List<Map<String, dynamic>>> getAllWithPagination(
       int page, int size) async {
    try {
            final response =
          await _helper.getGetApiResponse('$baseUrl/Ad8/Ad8/getall/page?page=$page&size=$size');
      final entities =
          (response['content'] as List).cast<Map<String, dynamic>>();
      return entities;
    } catch (e) {
      throw Exception('Failed to get all without pagination: $e');
    }
  }
  Future<Map<String, dynamic>> createEntity(
       Map<String, dynamic> entity) async {
    try {
            print("in post api$entity");
      final response =
          await _helper.getPostApiResponse('$baseUrl/Ad8/Ad8', entity);

      print(entity);

      // Assuming the response is a Map<String, dynamic>
      Map<String, dynamic> responseData = response;

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







  Future<void> updateEntity( int entityId, Map<String, dynamic> entity) async {
    try {
     await _helper.getPutApiResponse('$baseUrl/Ad8/Ad8/$entityId',
      entity);                print(entity);

    } catch (e) {
      throw Exception('Failed to update entity: $e');
    }
  }

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






}