namespace Hawkeye.VisionBuilder.Workflow.ColorStudioClasses;

public class CategoryTree
{
    public List<CategoryItem> CategoryItems { get; set; }=new List<CategoryItem>();

    public void Save(BinaryWriter writer)
    {
        writer.Write(CategoryItems.Count);
        foreach (var category in CategoryItems)
        {
            category.Save(writer);
        }
    }

    public static CategoryTree Load(BinaryReader reader)
    {
        var tree = new CategoryTree();
        var count = reader.ReadInt32();
        for (int i = 0; i < count; i++)
        {
            tree.CategoryItems.Add(CategoryItem.Load(reader));
        }
        return tree;
    }

    public static CategoryTree LoadFromFile(string path)
    {
        using var file = File.OpenRead(path);
        using var reader = new BinaryReader(file);
        return Load(reader);
    }
}