import type { Graph, Node, Edge } from '@antv/x6'
import { DrawOptions, DrawResult } from '../$draw/type'

type Point = { x: number; y: number }


export type PlanOptions = {
  
  sourcePoint: Point

  
  targetPoint: Point

  
  routes?: Point[][]

  
  obstacles?: { x: number; y: number; height: number; width: number }[]

  
  finderConfig?: {
    
    core?: 'AStar' | 'Dijkstra'

    
    grid?: { width: number; height: number }

    
    offset?: number

    
    allowDiagonal?: boolean

    
    dontCrossCorners?: boolean
  }
}

type perpendicularData = {
  
  perpendicularPoint: Point

  
  perpendicularLength: number
}


export type PlanResult = (
  | {
      sourceData: perpendicularData
      targetData: perpendicularData
      routeLength: number
      route: Point[]
    }
  | undefined
)[]

export type RouePlugin = {
  
  $route: {
    
    draw: (event: any, options?: DrawOptions) => DrawResult

    
    stopDraw: () => any

    
    getRoutes: (options?: any) => Point[][]

    
    getRouteNodes: (options?: any) => Node[]

    
    plan: (options?: PlanOptions) => Promise<PlanResult>

    
    drawObstacle: (event: any, options?: DrawOptions) => DrawResult

    
    stopDrawObstacle: () => any

    
    getObstacles: (options?: any) => Point[][]

    
    getObstacleNodes: (options?: any) => Node[]
  }
}

export type RouePluginOptions = {
  
  $route?: {
    
    draw?: DrawOptions

    
    drawObstacle?: DrawOptions

    
    plan?: PlanOptions
  }
}
