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 Adv1RepoScreen {
  final String baseUrl = ApiConstants.baseUrl;
  final BaseNetworkService _helper = NetworkApiService();

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

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








 Future<dynamic> fileupload_fieldUpload(
      String ref, String refTableNmae, FormData entity) async {
    try {
      String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
      final response = await _helper.getPostApiResponse(apiUrl, entity);
      return response;
    } catch (e) {
      throw Exception('Failed to Upload File: $e');
    }
  }

 Future<dynamic> fileupload_field2Upload(
      String ref, String refTableNmae, FormData entity) async {
    try {
      String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
      final response = await _helper.getPostApiResponse(apiUrl, entity);
      return response;
    } catch (e) {
      throw Exception('Failed to Upload File: $e');
    }
  }

 Future<dynamic> imageupload_fieldUpload(
      String ref, String refTableNmae, FormData entity) async {
    try {
      String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
      final response = await _helper.getPostApiResponse(apiUrl, entity);
      return response;
    } catch (e) {
      throw Exception('Failed to Upload Imageupload Field: $e');
    }
  }

 Future<dynamic> imageupload_field2Upload(
      String ref, String refTableNmae, FormData entity) async {
    try {
      String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
      final response = await _helper.getPostApiResponse(apiUrl, entity);
      return response;
    } catch (e) {
      throw Exception('Failed to Upload Imageupload Field2: $e');
    }
  }

 Future<dynamic> audio_fieldUpload(
      String ref, String refTableNmae, FormData entity) async {
    try {
      String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
      final response = await _helper.getPostApiResponse(apiUrl, entity);
      return response;
    } catch (e) {
      throw Exception('Failed to Upload File: $e');
    }
  }

 Future<dynamic> audio_field2Upload(
      String ref, String refTableNmae, FormData entity) async {
    try {
      String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
      final response = await _helper.getPostApiResponse(apiUrl, entity);
      return response;
    } catch (e) {
      throw Exception('Failed to Upload File: $e');
    }
  }

 Future<dynamic> video_fieldUpload(
      String ref, String refTableNmae, FormData entity) async {
    try {
      String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
      final response = await _helper.getPostApiResponse(apiUrl, entity);
      return response;
    } catch (e) {
      throw Exception('Failed to Upload File: $e');
    }
  }

 Future<dynamic> video_field2Upload(
      String ref, String refTableNmae, FormData entity) async {
    try {
      String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
      final response = await _helper.getPostApiResponse(apiUrl, entity);
      return response;
    } catch (e) {
      throw Exception('Failed to Upload File: $e');
    }
  }

}
