import 'package:didvan/models/content.dart';
import 'package:didvan/models/overview_data.dart';
import 'package:didvan/models/tag.dart';

class NewsDetailsData {
  final int id;
  final String title;
  final String reference;
  final String image;
  final String createdAt;
  bool marked;
  bool liked;
  int likes;
  int comments;
  final int order;
  final List<Tag> tags;
  final List<Content> contents;
  final List<OverviewData> relatedContents = [];
  bool relatedContentsIsEmpty;
  String? description;

  NewsDetailsData({
    required this.id,
    required this.title,
    required this.reference,
    required this.image,
    required this.createdAt,
    required this.marked,
    required this.liked,
    required this.likes,
    required this.comments,
    required this.tags,
    required this.contents,
    required this.order,
    this.relatedContentsIsEmpty = false,
    this.description,
  });

  factory NewsDetailsData.fromJson(Map<String, dynamic> json) {
    return NewsDetailsData(
      id: json['id'],
      title: json['title'],
      reference: json['reference'],
      image: json['image'],
      createdAt: json['createdAt'],
      marked: json['marked'],
      liked: json['liked'] ?? false,
      likes: json['likes'],
      comments: json['comments'],
      order: json['order'],
      description: json['description'],
      tags: List<Tag>.from(json['tags'].map((tag) => Tag.fromJson(tag))),
      contents: List<Content>.from(json['contents'].map(
        (content) => Content.fromJson(content),
      )),
    );
  }

  Map<String, dynamic> toJson() => {
        'id': id,
        'title': title,
        'order': order,
        'reference': reference,
        'image': image,
        'createdAt': createdAt,
        'marked': marked,
        'liked': liked,
        'likes': likes,
        'comments': comments,
        'description': description,
        'tags': tags.map((e) => e.toJson()).toList(),
        'contents': contents.map((e) => e.toJson()).toList(),
      };
}
