package com.yc.ship.module.resource.helper.entity;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2025/10/27 18:22
 */
public class TreeNode {

    public String id;

    public String parentId;

    public String name;

    public int number;

    List<TreeNode> children;

    public TreeNode(String id, String parentId, int number) {
        this.id = id;
        this.parentId = parentId;
        this.number = number;
        this.children = new ArrayList<>();
    }

    public void addChild(TreeNode child) {
        this.children.add(child);
    }

    public void calculateNumberSum() {
        for (TreeNode child : children) {
            child.calculateNumberSum();
            this.number += child.number;
        }
    }

    public String getId() {
        return id;
    }

    public List<TreeNode> getChildren() {
        return children;
    }

    @Override
    public String toString() {
        return "TreeNode{" +
                "id='" + id + '\'' +
                ", parentId='" + parentId + '\'' +
                ", name='" + name + '\'' +
                ", number=" + number +
                ", children=" + children +
                '}';
    }
}
