"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.buildPaginationParams = buildPaginationParams;
exports.buildSearchParams = buildSearchParams;
exports.buildUrl = buildUrl;
exports.safeJsonParse = safeJsonParse;
/**
 * Utility functions for common API patterns
 */

/**
 * Build URL search parameters from an object
 * @param params Object with parameter key-value pairs
 * @returns URLSearchParams instance
 */
function buildSearchParams(params) {
  const searchParams = new URLSearchParams();
  for (const [key, value] of Object.entries(params)) {
    if (value !== undefined && value !== null) {
      searchParams.append(key, value.toString());
    }
  }
  return searchParams;
}

/**
 * Build URL with search parameters
 * @param baseUrl Base URL
 * @param params Object with parameter key-value pairs
 * @returns Complete URL with search parameters
 */
function buildUrl(baseUrl, params) {
  if (!params) return baseUrl;
  const searchParams = buildSearchParams(params);
  const queryString = searchParams.toString();
  return queryString ? `${baseUrl}?${queryString}` : baseUrl;
}

/**
 * Common pagination parameters
 */

/**
 * Build pagination search parameters
 * @param params Pagination parameters
 * @returns URLSearchParams with pagination
 */
function buildPaginationParams(params) {
  return buildSearchParams(params);
}

/**
 * Common API response wrapper
 */

/**
 * Common error response wrapper
 */

/**
 * Safe JSON parsing with error handling
 * @param data Data to parse
 * @param fallback Fallback value if parsing fails
 * @returns Parsed data or fallback
 */
function safeJsonParse(data, fallback) {
  if (typeof data === 'string') {
    try {
      return JSON.parse(data);
    } catch {
      return fallback;
    }
  }
  return data;
}
//# sourceMappingURL=apiUtils.js.map