import 'package:rasadyar_core/presentation/utils/data_time_utils.dart';

Map<String, dynamic> buildQueryParams({
  Map<String, dynamic>? queryParams,
  String? search,
  String? value,
  int? page,
  int? pageSize,
  DateTime? fromDate,
  DateTime? toDate,
  String? role,
  String? state,
}) {
  final params = <String, dynamic>{};
  if (fromDate != null) {
    params['date1'] = fromDate.formattedDashedGregorian;
  }

  if (toDate != null) {
    params['date2'] = toDate.formattedDashedGregorian;
  }

  if (search != null && search.isNotEmpty) {
    params['search'] = search;
  }

  params['value'] = value ?? '';

  if (page != null) {
    params['page'] = page;
  }

  if (pageSize != null) {
    params['page_size'] = pageSize;
  }

  if (role != null && role.isNotEmpty) {
    params['role'] = role;
  }

  if (state != null && state.isNotEmpty) {
    params['state'] = state;
  }

  if (queryParams != null) {
    params.addAll(queryParams);
  }

  return params;
}

Map<String, dynamic>? buildRawQueryParams({
  Map<String, dynamic>? queryParams,
  String? search,
  String? value,
  int? page,
  int? pageSize,
  DateTime? fromDate,
  DateTime? toDate,
  String? role,
  String? state,
  double? centerLat,
  double? centerLng,
  double? radius,
}) {
  final params = <String, dynamic>{};
  if (fromDate != null) {
    params['date1'] = fromDate.formattedDashedGregorian;
  }

  if (toDate != null) {
    params['date2'] = toDate.formattedDashedGregorian;
  }

  if (search != null && search.isNotEmpty) {
    params['search'] = search;
  }

  if (value != null) {
    params['value'] = value ?? '';
  }

  if (page != null) {
    params['page'] = page;
  }

  if (pageSize != null) {
    params['page_size'] = pageSize;
  }

  if (role != null && role.isNotEmpty) {
    params['role'] = role;
  }

  if (state != null && state.isNotEmpty) {
    params['state'] = state;
  }

  if (queryParams != null) {
    params.addAll(queryParams);
  }

  if (centerLat != null) {
    params['center_lat'] = centerLat ?? '';
  }

  if (centerLng != null) {
    params['center_lon'] = centerLng ?? '';
  }

  if (radius != null) {
    params['radius'] = radius ?? '';
  }

  return params.keys.isEmpty ? null : params;
}
