// Organization chart AST structures package ast // OrganizationDiagram represents an organization chart type OrganizationDiagram struct { Root *OrganizationNode `json:"root"` Nodes []*OrganizationNode `json:"nodes"` Title *string `json:"title,omitempty"` Config map[string]any `json:"config,omitempty"` } type OrganizationNode struct { ID string `json:"id"` Name string `json:"name"` Title *string `json:"title,omitempty"` Department *string `json:"department,omitempty"` Level int `json:"level"` Children []*OrganizationNode `json:"children"` Parent *OrganizationNode `json:"parent,omitempty"` Icon *string `json:"icon,omitempty"` CssClasses []string `json:"cssClasses,omitempty"` Styles []string `json:"styles,omitempty"` } // Type returns the diagram type func (o *OrganizationDiagram) Type() DiagramType { return DiagramTypeOrganization } // Validate checks if the organization diagram is valid func (o *OrganizationDiagram) Validate() error { if o.Root == nil && len(o.Nodes) == 0 { return NewValidationError("organization diagram must have at least one node") } return nil } // NewOrganizationDiagram creates a new organization diagram func NewOrganizationDiagram() *OrganizationDiagram { return &OrganizationDiagram{ Nodes: make([]*OrganizationNode, 0), Config: make(map[string]any), } } // AddNode adds a node to the organization chart func (o *OrganizationDiagram) AddNode(node *OrganizationNode) { o.Nodes = append(o.Nodes, node) if o.Root == nil && node.Level == 0 { o.Root = node } } // FindNode finds a node by ID func (o *OrganizationDiagram) FindNode(id string) *OrganizationNode { for _, node := range o.Nodes { if node.ID == id { return node } } return nil } // AddChild adds a child node to a parent node func (node *OrganizationNode) AddChild(child *OrganizationNode) { child.Parent = node child.Level = node.Level + 1 node.Children = append(node.Children, child) }