class Category {
  final int id;
  final String name;
  final String? slug;
  final String? description;
  final int? parent;
  final int count;
  final String? imageUrl;

  Category({
    required this.id,
    required this.name,
    this.slug,
    this.description,
    this.parent,
    this.count = 0,
    this.imageUrl,
  });

  factory Category.fromJson(Map<String, dynamic> json) {
    return Category(
      id: json['id'] ?? 0,
      name: json['name'] ?? '',
      slug: json['slug'],
      description: json['description'],
      parent: json['parent'],
      count: json['count'] ?? 0,
      imageUrl: json['image']?['src'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'slug': slug,
      'description': description,
      'parent': parent,
      'count': count,
      'image': imageUrl != null ? {'src': imageUrl} : null,
    };
  }
}

