import { deleteCookie } from 'h3'
import { handleApiError, createSuccessResponse } from '../../utils/errors'

interface StopImpersonationResponse {
  message: string
}

export default defineEventHandler(async (event) => {
  try {
    // Clear impersonation marker
    deleteCookie(event, 'impersonateUserId')
    return createSuccessResponse<StopImpersonationResponse>({
      message: 'Impersonation ended'
    })
  } catch (error) {
    throw handleApiError(error)
  }
})
