// Create a new Helcim payment plan
import { createHelcimPlan } from '../../utils/helcim.js'

export default defineEventHandler(async (event) => {
  try {
    await requireAdmin(event)
    const body = await validateBody(event, helcimCreatePlanSchema)

    const planData = await createHelcimPlan({
      planName: body.name,
      planAmount: parseFloat(body.amount),
      planFrequency: body.frequency,
      planCurrency: body.currency || 'CAD'
    })

    return {
      success: true,
      plan: planData
    }

  } catch (error) {
    if (error.statusCode) throw error
    console.error('Error creating Helcim payment plan:', error)
    throw createError({
      statusCode: 500,
      statusMessage: 'An unexpected error occurred'
    })
  }
})
