export default defineEventHandler(async (event) => {
  const query = getQuery(event)
  const parent = JSON.parse(query.parent)

  if (parent._id !== 'ID') {
    return {}
  }

  try {
    const results = await prisma.address.findMany({
      select: {
        id: true,
        name: true,
      },
    })
    return results.map((r) => {
      return {
        _id: r.id,
        name: r.name,
      }
    })
  } catch (error) {
    // Return error if fetching users fails
    return {
      status: 500,
      body: { message: 'Failed to fetch states' },
    }
  }
})
