import { getNearbyTrees, getTreeById } from '@/mock/tree'
import { request } from './request'

const USE_MOCK = false

export async function fetchNearbyTrees(lng: number, lat: number, maxDistance = 10000, limit = 100) {
  if (USE_MOCK) return getNearbyTrees(lng, lat, maxDistance, limit)

  const res = await request<any[]>('/mobile/wishingtree/list', {
    method: 'POST',
    body: JSON.stringify({ lng, lat, maxDistance, limit }),
  })
  return res.data.map((item: any) => ({
    ...item,
    isInRange: item.isInRange ?? false,
  }))
}

export async function fetchTreeDetail(id: number) {
  if (USE_MOCK) return getTreeById(id)

  const res = await request<any>(`/mobile/wishingtree/${id}`)
  return res.data
}
