import { apiRoute } from '@/lib/api/handler'
import { ApiError, ERROR_CODES } from '@/lib/api/errors'
import { getConnector } from '@/lib/services/integration-service'

export const dynamic = 'force-dynamic'

/** One connector: configuration, mappings, health history, events and the flow view. */
export const GET = apiRoute<{ code: string }>(
  { permission: 'integrations.read' },
  async ({ params }) => {
    const connector = await getConnector(params.code)
    if (!connector) throw new ApiError(ERROR_CODES.notFound)
    return connector
  },
)
