import { Position } from '@vue-flow/core'
import type { OnConnectStartParams, Node, DefaultEdge, ViewportTransform } from '@vue-flow/core'

export * from '@vue-flow/core'

export type CanvasConnectionPort = {
	node?: string
	type: string
	index: number
	required?: boolean
	maxConnections?: number
	label?: string
	[key: string]: any
}

export interface CanvasElementPortWithRenderData extends CanvasConnectionPort {
	handleId: string
	connectionsCount: number
	isConnecting: boolean
	position: Position
	offset?: { top?: string; left?: string }
}

export type CanvasExecutionStatus = 'idle' | 'running' | 'success' | 'warning' | 'suspended'
export interface IWorkflowNode extends Node {
	appAgentId: string
	name?: string
	remark?: string
	nodeType: string
	parentId?: string
	selected?: boolean
	executionStatus?: CanvasExecutionStatus
	data: {
		id: string
		// 位置
		position: XYPosition
		// 宽度
		width: number
		// 高度
		height: number
		// 节点层级
		zIndex?: number
		// 节点类型
		nodeType: string
		executionStatus?: CanvasExecutionStatus
		// 定义节点数据
		[key: string]: any
	}
}

export type IWorkflowEdge = DefaultEdge<{
	// 定义边数据
	[key: string]: any
}>

export interface IWorkflow {
	id: string
	name: string
	tags?: string[]
	description?: string
	status?: 'published' | 'draft' | 'deleted'
	nodes: IWorkflowNode[]
	edges: IWorkflowEdge[]
	viewport?: ViewportTransform
	[key: string]: any
}

export interface XYPosition {
	x: number
	y: number
}

export type ConnectStartEvent = {
	event?: MouseEvent | undefined
} & OnConnectStartParams

export type CanvasNodeMoveEvent = { id: string; position: IWorkflowNode['position'] }

export { Position }
