import 'package:cheminova/models/rd_get_order_model.dart';

import '../utils/api_urls.dart';
import '../utils/common_api_service.dart';

class GetProductRDService {
  // Method to fetch product manuals using an authorization token
  Future<List<PlacedOrdersResponse>?> getRDProducts(String token) async {
    try {
      String url = ApiUrls.getRdOrderUrl; // Base URL to fetch product manuals

      final response = await commonApiService<List<PlacedOrdersResponse>>(
        method: "GET",
        url: url,
        additionalHeaders: {  // Pass the token here
          'Authorization': 'Bearer $token',
        },
        fromJson: (json) {
          if (json['plcaedOrders'] != null) {
            // If the productManuals key is present, map the response to a list of ProductManualModel objects
            final List<PlacedOrdersResponse> productManuals = (json['plcaedOrders'] as List)
                .map((manualJson) => PlacedOrdersResponse.fromJson(manualJson))
                .toList();
            return productManuals; // Return the list of product manuals
          } else {
            return [];
          }
        },
      );
      return response;
    } catch (e) {

      print("fkfgghgh ,${e.toString()}");
      //print(e.toString());
      return null;
    }
  }





  Future<List<PlacedOrdersResponse>?> getRDPendingProduct(String token) async {
    try {
      String url = ApiUrls.getRdPendingOrdergUrl; // Base URL to fetch product manuals

      final response = await commonApiService<List<PlacedOrdersResponse>>(
        method: "GET",
        url: url,
        additionalHeaders: {  // Pass the token here
          'Authorization': 'Bearer $token',
        },
        fromJson: (json) {
          if (json['plcaedOrders'] != null) {
            // If the productManuals key is present, map the response to a list of ProductManualModel objects
            final List<PlacedOrdersResponse> productManuals = (json['plcaedOrders'] as List)
                .map((manualJson) => PlacedOrdersResponse.fromJson(manualJson))
                .toList();
            return productManuals; // Return the list of product manuals
          } else {
            return [];
          }
        },
      );
      return response;
    } catch (e) {

      print("fkfgghgh ,${e.toString()}");
      //print(e.toString());
      return null;
    }
  }


  Future<List<PlacedOrdersResponse>?> getRDCancleProduct(String token) async {
    try {
      String url = ApiUrls.getrdCancleOrderUrl; // Base URL to fetch product manuals

      final response = await commonApiService<List<PlacedOrdersResponse>>(
        method: "GET",
        url: url,
        additionalHeaders: {  // Pass the token here
          'Authorization': 'Bearer $token',
        },
        fromJson: (json) {
          if (json['plcaedOrders'] != null) {
            // If the productManuals key is present, map the response to a list of ProductManualModel objects
            final List<PlacedOrdersResponse> productManuals = (json['plcaedOrders'] as List)
                .map((manualJson) => PlacedOrdersResponse.fromJson(manualJson))
                .toList();
            return productManuals; // Return the list of product manuals
          } else {
            return [];
          }
        },
      );
      return response;
    } catch (e) {

      print("fkfgghgh ,${e.toString()}");
      //print(e.toString());
      return null;
    }
  }



}