export default defineTask({
  meta: {
    name: 'create-super-admin',
    description: 'Promote a user (by email) to super admin'
  },
  async run({ payload }) {
    if (!import.meta.dev) {
      throw new Error('This task can only be run in development environment')
    }
    const email = (payload?.email || '').toString()
    if (!email) {
      throw new Error('Email is required')
    }
    const db = useDB()
    const { user } = await import('../database/schema')
    const { eq } = await import('../utils/database')
    const [record] = await db
      .update(user)
      .set({ superAdmin: true, emailVerified: true })
      .where(eq(user.email, email))
      .returning({ id: user.id, email: user.email, superAdmin: user.superAdmin })
    return { result: record }
  }
})
