import 'dart:convert';
import 'package:cheminova/controller/place_order_service.dart';
import 'package:cheminova/models/product_model.dart';
import 'package:dio/dio.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../models/oder_place_model.dart';


class OrderPlacedController extends GetxController {
  var placedOrder1 = PlacedOrderModel(
    paymentMode: 'cheque',
    shipTo: '456, Park Street, Kolkata, West Bengal - 700016',
    billTo: '456, Park Street, Kolkata, West Bengal - 700016',
    subtotal: 300,
    gstTotal: 100,
    grandTotal: 400,
    orderItems: [
    ],
  ).obs;

  var isLoading = false.obs;

  final OrderPlacedService _orderPlacedService = OrderPlacedService();

  Future<void> placeOrder() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String? token = prefs.getString('token');
    isLoading.value = true;
    //try {
      // Construct order details
      PlacedOrderModel orderDetails = placedOrder1.value;
      print("Order Details: $orderDetails");

      // Call the service to place the order
     await _orderPlacedService.placeOrder(orderDetails, token!);

    }
    // catch (e) {
    //
    // } finally {
    //   isLoading.value = false;
    // }
  }
