using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RedundancyFinder
{
    using System;
    using System.Collections.Generic;

    using System;
    using System.Collections.Generic;

    public class DirectoryNode
    {
        public string Name { get; set; }
        public List<DirectoryNode> Children { get; private set; }

        public DirectoryNode(string name)
        {
            Name = name;
            Children = new List<DirectoryNode>();
        }

        public void AddChild(DirectoryNode child)
        {
            Children.Add(child);
        }

        public void RemoveChild(DirectoryNode child)
        {
            Children.Remove(child);
        }

        public void Traverse(int level = 0)
        {
            Console.WriteLine(new string(' ', level * 2) + Name);
            foreach (var child in Children)
            {
                child.Traverse(level + 1);
            }
        }

        public DirectoryNode? Find(string name)
        {
            if (Name == name)
                return this;

            foreach (var child in Children)
            {
                var result = child.Find(name);
                if (result != null)
                    return result;
            }

            return null;
        }
    }


}
