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

  try {
    const cities = await prisma.addressCities.findMany({
      where: {
        Parent: parent.Code,
      },
    })
    return cities.map((c) => {
      return {
        Code: c.Code,
        Name: c.Name,
      }
    })
  } catch (error) {
    // Return error if fetching users fails
    return {
      status: 500,
      body: { message: 'Failed to fetch cities' },
    }
  }
})
