module Prism
  class DotVisitor < Visitor
    class Field
      attr_reader name: String
      attr_reader value: String?
      attr_reader port: bool

      def initialize: (String name, String? value, bool port) -> void
      def to_dot: () -> String
    end

    class Table
      attr_reader name: String
      attr_reader fields: Array[Field]

      def initialize: (String name) -> void
      def field: (String name, ?String? value, ?port: bool) -> void
      def to_dot: () -> String
    end

    class Digraph
      attr_reader nodes: Array[String]
      attr_reader waypoints: Array[String]
      attr_reader edges: Array[String]

      def initialize: () -> void
      def node: (String value) -> void
      def waypoint: (String value) -> void
      def edge: (String value) -> void

      def to_dot: () -> String
    end

    attr_reader digraph: Digraph

    private

    def node_id: (Prism::node node) -> String
    def location_inspect: (Location location) -> String

    <%- flags.each do |flag| -%>
    def <%= flag.human %>_inspect: (<%= nodes.filter_map { |node| node.name if node.flags == flag }.join(" | ") %> node) -> String
    <%- end -%>
  end
end
