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

import 'content.dart';
import 'tag.dart';

class RadarDetailsData {
  final int id;
  final String title;
  final String image;
  final int timeToRead;
  final String createdAt;
  final String? podcast;
  final int? duration;
  final bool forManagers;
  bool marked;
  int comments;
  final List<Tag> tags;
  final List<Content> contents;
  final List<CategoryData> categories;
  final int order;
  final List<OverviewData> relatedContents = [];
  bool relatedContentsIsEmpty;
  String? description;

  RadarDetailsData({
    required this.id,
    required this.title,
    required this.image,
    required this.timeToRead,
    required this.createdAt,
    required this.podcast,
    required this.forManagers,
    required this.marked,
    required this.comments,
    required this.tags,
    required this.contents,
    required this.categories,
    required this.order,
    required this.duration,
    this.relatedContentsIsEmpty = false,
    this.description,
  });

  factory RadarDetailsData.fromJson(Map<String, dynamic> json) {
    return RadarDetailsData(
      id: json['id'],
      title: json['title'],
      image: json['image'],
      timeToRead: json['timeToRead'],
      createdAt: json['createdAt'],
      podcast: json['podcast'],
      forManagers: json['forManagers'],
      marked: json['marked'],
      order: json['order'],
      comments: json['comments'],
      tags: List<Tag>.from(json['tags'].map((tag) => Tag.fromJson(tag))),
      contents: List<Content>.from(
        json['contents'].map(
          (content) => Content.fromJson(content),
        ),
      ),
      categories: List<CategoryData>.from(
        json['categories'].map(
          (cat) => CategoryData.fromJson(cat),
        ),
      ),
      duration: json['duration'],
      description: json['description'],
    );
  }

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