import 'dart:convert';
import 'dart:developer';

import 'package:cheminova/models/product_model.dart';
import 'package:dio/dio.dart';

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

class OrderPlacedService {
  final Dio dio = Dio();

  Future<void> placeOrder(PlacedOrderModel orderDetails, String token) async {
    //try {
    logger.w("orderjson ${jsonEncode(orderDetails.toJson())}");
      final response = await dio.post(
        'https://cheminova-api-2.onrender.com/api/order-place', // Ensure this is your correct endpoint
        data: jsonEncode(orderDetails.toJson()),
        options: Options(
          headers: {
            'Authorization': 'Bearer $token',
            'Content-Type': 'application/json',
          },
        ),
      );
      logger.w("Status code,${response.statusCode}");
      if (response.statusCode != 201) {

        throw Exception('Failed to place order');
      }
    }
    // on DioException catch (e) {
    //   print("DioException: ${e.message}");
    //   throw Exception('Failed to place order: ${e.message}');
    // }
    // catch (e) {
    //   print("General Exception: ${e.toString()}");
    //   throw Exception('Failed to place order: ${e.toString()}');
    // }
  }

