class AdminCategoryNode {
  final int id;
  final String name;
  final int? parentId;
  final List<AdminCategoryNode> children;

  const AdminCategoryNode({
    required this.id,
    required this.name,
    required this.parentId,
    required this.children,
  });

  factory AdminCategoryNode.fromJson(Map<String, dynamic> json) =>
      AdminCategoryNode(
        id: (json['id'] as num).toInt(),
        name: (json['name'] ?? '').toString(),
        parentId: (json['parentId'] as num?)?.toInt(),
        children: ((json['children'] as List<dynamic>?) ?? const [])
            .map((child) =>
                AdminCategoryNode.fromJson(child as Map<String, dynamic>))
            .toList(),
      );
}