import type { RouteLocationRaw } from 'vue-router'
import type { EntityRefDto, EntityType } from '../api/contracts'

export function routeForEntity(entity: EntityRefDto): RouteLocationRaw {
  const id = entity.id
  switch (entity.type) {
    case 'activity':
      return { name: 'Activity', query: { event: id } }
    case 'agent':
      return { name: 'AgentDetail', params: { id } }
    case 'agent-proposal':
      return { name: 'AgentProposalDetail', params: { proposalId: id } }
    case 'project':
      return { name: 'ProjectDetail', params: { id } }
    case 'task':
      return { name: 'TaskDetail', params: { id } }
    case 'run':
      return { name: 'RunDetail', params: { id } }
    case 'cron':
      return { name: 'Calendar', query: { job: id } }
    case 'incident':
      return { name: 'Incidents', query: { incident: id } }
    case 'document':
      return { name: 'Docs', query: { document: id } }
    case 'notification':
      return { name: 'Notifications', query: { notification: id } }
    case 'task-board':
      return { name: 'Task Board' }
    case 'openclaw-task':
      return { name: 'Run Control', query: { task: id } }
    case 'session':
      return { name: 'Run Control', query: { session: id } }
    case 'approval':
      return { name: 'Run Control', query: { approval: id } }
    case 'config':
      return { name: 'Settings', query: { section: 'openclaw-config' } }
    case 'agent-file': {
      const separator = id.indexOf('/')
      const agentId = separator >= 0 ? id.slice(0, separator) : id
      const fileName = separator >= 0 ? id.slice(separator + 1) : undefined
      return {
        name: 'AgentDetail',
        params: { id: agentId },
        query: fileName ? { file: fileName } : undefined,
      }
    }
    case 'event-stream':
      return { name: 'Settings', query: { section: 'openclaw-events' } }
  }
}

export function entityTypeLabel(type: EntityType): string {
  const labels: Record<EntityType, string> = {
    activity: 'Aktivität',
    agent: 'Agent',
    'agent-proposal': 'Agent-Vorschlag',
    project: 'Projekt',
    task: 'Aufgabe',
    run: 'Run',
    cron: 'Cronjob',
    incident: 'Incident',
    document: 'Dokument',
    notification: 'Benachrichtigung',
    'task-board': 'Task Board',
    'openclaw-task': 'OpenClaw-Task',
    session: 'Session',
    approval: 'Freigabe',
    config: 'Konfiguration',
    'agent-file': 'Agent-Datei',
    'event-stream': 'Ereignisstream',
  }
  return labels[type]
}
