import { duplicateTemplate } from '../../../utils/templates'

export default defineEventHandler(async (event) => {
  const id = getRouterParam(event, 'id')

  if (!id) {
    throw createError({
      statusCode: 400,
      message: 'ID requerido'
    })
  }

  const template = await duplicateTemplate(id)

  if (!template) {
    throw createError({
      statusCode: 404,
      message: 'Template no encontrado'
    })
  }

  return template
})
