import 'package:didvan/models/category.dart';

class OverviewData {
  final int id;
  final String title;
  final String image;
  final String description;
  final int? timeToRead;
  final String? reference;
  final bool forManagers;
  final String createdAt;
  final String type;
  int comments;
  bool marked;
  final List<CategoryData>? categories;

  OverviewData({
    required this.id,
    required this.title,
    required this.image,
    required this.description,
    required this.createdAt,
    required this.type,
    required this.marked,
    required this.comments,
    required this.forManagers,
    this.timeToRead,
    this.reference,
    this.categories,
  });

  factory OverviewData.fromJson(Map<String, dynamic> json) => OverviewData(
        id: json['id'],
        title: json['title'],
        image: json['image'],
        description: json['description'],
        timeToRead: json['timeToRead'],
        reference: json['reference'],
        forManagers: json['forManagers'] ?? false,
        comments: json['comments'] ?? 0,
        createdAt: json['createdAt'],
        type: json['type'] ?? '',
        marked: json['marked'] ?? false,
        categories: (json['categories'] as List<dynamic>?)
            ?.map((e) => CategoryData.fromJson(e as Map<String, dynamic>))
            .toList(),
      );

  Map<String, dynamic> toJson() => {
        'id': id,
        'title': title,
        'image': image,
        'description': description,
        'timeToRead': timeToRead,
        'reference': reference,
        'forManagers': forManagers,
        'createdAt': createdAt,
        'type': type,
        'categories': categories?.map((e) => e.toJson()).toList(),
      };
}
