import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:nearle/models/summary/deliverystats.dart';
import 'package:nearle/views/helpers/constants/apiconstants.dart';

class SummaryProvider {
  final String baseUrl = ApiConstants.summaryApiLive;

  Future<DeliveryStats?> fetchSummaryStats(int userId) async {
    final url = Uri.parse('$baseUrl/getdeliverystats?userid=$userId');

    try {
      print(url);
      final response = await http.get(url);

      if (response.statusCode == 200) {
        final decoded = jsonDecode(response.body);
        if (decoded['status'] == true && decoded['data'] != null) {
          return DeliveryStats.fromJson(decoded['data']);
        } else {
          print('API returned false status: ${decoded['message']}');
        }
      } else {
        print('something went wrong');
      }
    } catch (e) {
      print('something went wrong');
    }
    return null;
  }
}


