import '../../../modules/profile/customer_request.dart';
import '../../../service/dio.dart';

class CustomerRequestRepository {
  final CustomDio _dio = CustomDio();

  /// Create a new customer request
  Future<dynamic> createCustomerRequest(CustomerRequestModel model) async {
    const String url = "https://fiesta.nearle.app/live/api/v1/mob/customers/createcustomerrequest";
    try {
      final response = await _dio.postData(url, model.toJson());
      print("POST URL: $url");
      print("Payload: ${model.toJson()}");
      print("Response: $response");
      return response;
    } catch (e) {
      return {"status": false, "message": e.toString()};
    }
  }

  /// Fetch customer requests (status)
  Future<List<CustomerRequestStatusModel>> fetchCustomerRequests({
    required int customerId,
    int pageNo = 1,
    int pageSize = 10,
  }) async {
    final String url = "https://fiesta.nearle.app/live/api/v1/mob/customers/getcustomerrequests"
        "?customerid=$customerId&pageno=$pageNo&pagesize=$pageSize";

    try {
      final response = await _dio.getData(url); // assuming getData exists
      print("GET URL: $url");
      print("Response: $response");

      if (response != null && response['status'] == true) {
        final List data = response['data'] ?? [];
        return data.map((e) => CustomerRequestStatusModel.fromJson(e)).toList();
      }
      return [];
    } catch (e) {
      print("❌ Fetch error: $e");
      return [];
    }
  }
}
