import 'dart:convert';
import 'package:NearleDailyBusiness/Helper/Logger.dart';
import 'package:http/http.dart' as http;

import '../../../Model/Response/Orders/Getorderresponse.dart';


class OrdersProvider {
  Future<GetOrders?> getOrders(String url) async {
    try {
      print('🌐 GetOrderUrl : $url');
      final response = await http.get(Uri.parse(url));

      print('📦 Response Status: ${response.statusCode}');
      print('📦 Response Body: ${response.body}');

      if (response.statusCode == 200) {
        final data = jsonDecode(response.body);

        logger.i("GetOrders Response: ${jsonEncode(data)}");

        return GetOrders.fromJson(data);
      } else {
        print('❌ Failed to load orders: ${response.reasonPhrase}');
        return null;
      }
    } catch (e) {
      print('🚨 Exception in getOrders: $e');
      return null;
    }
  }
}
