/// A WooCommerce product category.
class ProductCategory {
  /// WooCommerce category ID.
  final int id;

  /// Display name of the category.
  final String name;

  /// URL-friendly slug.
  final String slug;

  /// Parent category ID, or 0 if top-level.
  final int parentId;

  /// Number of products in this category.
  final int count;

  const ProductCategory({
    required this.id,
    required this.name,
    required this.slug,
    required this.parentId,
    required this.count,
  });

  /// Returns a copy of this [ProductCategory] with the given fields replaced.
  ProductCategory copyWith({int? id, String? name, String? slug, int? parentId, int? count}) {
    return ProductCategory(
      id: id ?? this.id,
      name: name ?? this.name,
      slug: slug ?? this.slug,
      parentId: parentId ?? this.parentId,
      count: count ?? this.count,
    );
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is ProductCategory &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          name == other.name &&
          slug == other.slug &&
          parentId == other.parentId &&
          count == other.count;

  @override
  int get hashCode => Object.hash(id, name, slug, parentId, count);

  @override
  String toString() => 'ProductCategory(id: $id, name: $name, slug: $slug)';
}
