import 'dart:convert';
import 'package:http/http.dart';

import '../../../Helper/Logger.dart';
import '../../../Model/Request/Createorder/Createorderrequest.dart';
import '../../../Model/Response/Createorder/CreateOrderResponsemodel.dart';

class CreateOrderProviders{
  Future<CreateOrderResponse?> createOrder(CreateOrder data,String urldata,) async {
    CreateOrderResponse? createOrder;
    try {

      final url = Uri.parse(urldata);

      final response = await post(url,
          body: json.encode(data),
          headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            // 'Authorization': '$token',
          });

      print('CreateOrderresponsebody ${response.body}');
      print('CreateOrderdatatoJson ${data.toJson()}');
      print('pickuplocationid ${data.pickup?.customerid}');
      print('droplocationid ${data.drop?.customerid}');
        logger.i(json.encode(data.toJson()));

      // print('headerssssssssss ${response.headers}');
      print('CreateOrderurlsssssssssss ${urldata.toString()}');
      Map<String, dynamic> parsedJson = json.decode(response.body.toString());

      createOrder = CreateOrderResponse.fromJson(parsedJson);
      print('createOrderinprovider${createOrder}');

    } catch (e) {
      print(e.toString());
      print("error");
    }
    return createOrder;
  }

}

