// lib/controllers/order_controller/create_order_controller.dart
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../domain/provider/order/create_order.dart';
import '../../modules/orders/create_order.dart';

class OrderController extends GetxController {
  final CreateOrderProvider provider = CreateOrderProvider();
  var isLoading = false.obs;
  String? lastError; // 👈 add this

  Future<CreateOrderResponse?> createOrder(CreateOrderRequest request) async {
    try {
      isLoading.value = true;

      final response = await provider.createOrder(request);

      isLoading.value = false;

      if (response.status == 'accepted') {
        print(response.status);
        print("✅ Order Success");
      } else {
        print("❌ Order Failed");
      }

      return response;
    } catch (e) {
      isLoading.value = false;

      print("🔥 ERROR: $e");           // already printing e here
      print("🔥 ERROR TYPE: ${e.runtimeType}"); // 👈 add this to see the exact class

      return null;
    }
  }}
