import 'dart:convert';
import 'package:http/http.dart';
import 'package:http/http.dart' as http;
import '../../../Helper/Logger.dart';
import '../../../Model/Request/create_delivery_request/create_delivery_request.dart';
import '../../../Model/Response/create_delivery_response/create_delivery_request.dart';

class CreateDeliveryProvider {

  Future<CreateDeliveryResponse?> createDelivery(List<CreateDelivery> data,String urldata,) async {

    CreateDeliveryResponse? createDeliveryResponse;
    logger.i('Url data for crate delivery : $urldata');
    logger.i('Json Encode : ${json.encode(data)}');
    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',
          });

      logger.i('create Delivery : ${response.body}');

      Map<String, dynamic> parsedJson = json.decode(response.body);

      createDeliveryResponse = CreateDeliveryResponse.fromJson(parsedJson);

    } catch (e) {
      logger.i(e.toString());
      logger.i("error");
    }
    return createDeliveryResponse;
  }




}