/// 分类/筛选模型
/// 
/// 对应 Supabase 中的 categories 表
class CategoryModel {
  final String id;
  final String code;
  final String label;
  final int sortOrder;
  final bool isActive;
  final DateTime? createdAt;

  const CategoryModel({
    required this.id,
    required this.code,
    required this.label,
    this.sortOrder = 0,
    this.isActive = true,
    this.createdAt,
  });

  factory CategoryModel.fromJson(Map<String, dynamic> json) {
    return CategoryModel(
      id: json['id'] as String,
      code: json['code'] as String,
      label: json['label'] as String,
      sortOrder: json['sort_order'] as int? ?? 0,
      isActive: json['is_active'] as bool? ?? true,
      createdAt: json['created_at'] != null
          ? DateTime.parse(json['created_at'] as String)
          : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'code': code,
      'label': label,
      'sort_order': sortOrder,
      'is_active': isActive,
    };
  }
}
