//
//  Node.swift - DOMの基底インタフェース
//  XMLDOMParser
//
//  Created by EnchantCode on 2021/05/03.
//

import Foundation

public protocol Node: CustomStringConvertible {
    var uuid: NSUUID {get}
    
    var tagName: String { get }
    var parent: Node? { get set }
    var children: [Node] { get set }
    var description: String { get }
    
    mutating func appendChild(_ node: Node)
    mutating func removeChild(_ node: Node)
}

public extension Node {
    
    mutating func appendChild(_ node: Node){
        var node = node
        node.parent = self
        self.children.append(node)
    }
    
    mutating func removeChild(_ node: Node){
        self.children = self.children.filter({$0.uuid != node.uuid})
    }
}
