import 'package:cheminova/controller/product_mannual_service.dart';
import 'package:cheminova/controller/rd_get_order_service.dart';
import 'package:cheminova/models/rd_get_order_model.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../models/product_mannual_model.dart'; // Your model import
// Your service import

class GetProductRDController extends GetxController {
  var isLoading = true.obs; // Tracks the loading state
  var productRDList = <PlacedOrdersResponse>[].obs; // List of products

  @override
  void onInit() {
    fetchRDProduct();
    super.onInit();
  }

  // Fetch the products from the API
  Future<void> fetchRDProduct() async {
    try {
      SharedPreferences prefs = await SharedPreferences.getInstance();
      String? token = prefs.getString('token');
      isLoading(true); // Start loading
      final  response = await GetProductRDService().getRDProducts(token!); // Fetch products from API
      if (response != null) {
        productRDList.assignAll(response); // Assign products to the observable list
      }
    } finally {
      isLoading(false); // End loading
    }
  }



  Future<void> getRDPendingProduct() async {
    try {
      SharedPreferences prefs = await SharedPreferences.getInstance();
      String? token = prefs.getString('token');
      isLoading(true); // Start loading
      final  response = await GetProductRDService().getRDPendingProduct(token!); // Fetch products from API
      if (response != null) {
        productRDList.assignAll(response); // Assign products to the observable list
      }
    } finally {
      isLoading(false); // End loading
    }
  }



  Future<void> getRDCancleProduct() async {
    try {
      SharedPreferences prefs = await SharedPreferences.getInstance();
      String? token = prefs.getString('token');
      isLoading(true); // Start loading
      final  response = await GetProductRDService().getRDCancleProduct(token!); // Fetch products from API
      if (response != null) {
        productRDList.assignAll(response); // Assign products to the observable list
      }
    } finally {
      isLoading(false); // End loading
    }
  }
}

