/**
 * Build the flat query contract used by water-facility list and export APIs.
 * The legacy addDateRange helper nests beginTime/endTime under params; these
 * endpoints deliberately expose startTime/endTime at the top level instead.
 */
export function buildWaterFacilityQuery(queryParams = {}, dateRange = []) {
  const query = { ...queryParams }
  delete query.params
  delete query.beginTime
  delete query.endTime
  delete query.startTime

  const range = Array.isArray(dateRange) ? dateRange : []
  if (range[0]) query.startTime = range[0]
  if (range[1]) query.endTime = range[1]
  return query
}

export function normalizePipeStatus(status) {
  return status === null || status === undefined ? '' : String(status)
}

export function getRequestErrorMessage(error, fallback) {
  return error?.response?.data?.msg || error?.response?.data?.message || error?.message || fallback
}
