import type { Edge, Node } from '@vue-flow/core'
import type { BusinessDependency, BusinessSystemItem, BusinessTopologyEdge, BusinessTopologyNode } from '@/api/ops/businessSystem'

export type BusinessTopologyViewMode = 'business' | 'resource' | 'dependency'

export type BusinessTopologyHealthFilter = 'all' | 'healthy' | 'degraded' | 'critical' | 'unknown'

export type BusinessTopologyNodeKind = 'business' | 'resource'

export type BusinessTopologyEdgeKind = 'business_dependency' | 'resource_link'

export interface BusinessTopologyBusinessNodeData {
  kind: 'business'
  label: string
  status: string
  healthScore?: number
  businessSystem?: BusinessSystemItem
  dependency?: BusinessDependency
  resourceUID?: never
  resourceType?: never
  topologyNode?: never
}

export interface BusinessTopologyResourceNodeData {
  kind: 'resource'
  label: string
  status: string
  resourceUID?: string
  resourceType?: string
  topologyNode?: BusinessTopologyNode
  healthScore?: never
  businessSystem?: never
  dependency?: never
}

export type BusinessTopologyGraphNodeData = BusinessTopologyBusinessNodeData | BusinessTopologyResourceNodeData

export interface BusinessTopologyDependencyEdgeData {
  kind: 'business_dependency'
  label: string
  status?: string
  dependency?: BusinessDependency
  topologyLink?: never
}

export interface BusinessTopologyResourceLinkEdgeData {
  kind: 'resource_link'
  label: string
  status?: string
  topologyLink?: BusinessTopologyEdge
  dependency?: never
}

export type BusinessTopologyGraphEdgeData = BusinessTopologyDependencyEdgeData | BusinessTopologyResourceLinkEdgeData

export type BusinessTopologyFlowNode = Node<BusinessTopologyGraphNodeData, any, 'businessTopology'>

export type BusinessTopologyFlowEdge = Edge<BusinessTopologyGraphEdgeData>

export interface BusinessTopologyGraph {
  nodes: BusinessTopologyFlowNode[]
  edges: BusinessTopologyFlowEdge[]
}

export type BusinessTopologySelection =
  | { type: 'node'; id: string; data: BusinessTopologyGraphNodeData }
  | { type: 'edge'; id: string; data: BusinessTopologyGraphEdgeData }
