/**
 * 将 /bigScreen/home/townMapMarkers 响应转为地图标注覆盖表
 * @param {Array<{ townName: string, yakInventoryCount?: number, yakOutboundCount?: number }>} markers
 * @returns {Record<string, { inventory: number, outbound: number }>}
 */
export function markersToTownshipLabels(markers) {
  const labels = {}
  if (!Array.isArray(markers)) {
    return labels
  }
  markers.forEach((item) => {
    const name = item?.townName != null ? String(item.townName).trim() : ''
    if (!name) {
      return
    }
    labels[name] = {
      inventory: item.yakInventoryCount != null ? Number(item.yakInventoryCount) : 0,
      outbound: item.yakOutboundCount != null ? Number(item.yakOutboundCount) : 0
    }
  })
  return labels
}

/** 按乡镇名取存栏/出栏标注（仅使用接口或 props 传入的数据） */
export function getTownshipLivestockStats(name, overrides = {}) {
  const custom = overrides?.[name]
  if (!custom || typeof custom !== 'object') {
    return null
  }
  return {
    inventory: custom.inventory != null ? custom.inventory : 0,
    outbound: custom.outbound != null ? custom.outbound : 0
  }
}
