class ExerciseTree {
  /// treeId
  late int treeId;

  /// parentId
  late int parentId;

  /// name
  late String name;

  /// imageUrl
  late String imageUrl;

  /// active
  late bool active;

  /// nameTranslation
  late String nameTranslation;

  /// sort
  int? sort;

  String? internalName;

  String? description;
  String? descriptionTranslation;

  ExerciseTree();

  ExerciseTree.fromJson(Map json) {
    this.treeId = json['treeId'];
    this.name = json['name'];
    this.parentId = 0;
    this.imageUrl = json['imageUrl'];
    this.active = json['active'];
    this.nameTranslation = json['translations'] != null && (json['translations']).length > 0 ? json['translations'][0]['name'] : this.name;
    this.descriptionTranslation =
        json['translations'] != null && (json['translations']).length > 0 && json['translations'][0]['description'] != null
            ? json['translations'][0]['description']
            : this.description;
    this.sort = 99;
    this.internalName = json['internalName'];
  }

  Map<String, dynamic> toJson() {
    return {
      "treeId": treeId,
      "parentId": parentId,
      "name": name,
      "description": description,
      "imageUrl": imageUrl,
      "active": active.toString(),
      "nameTranslation": nameTranslation,
      "descriptionTranslation": descriptionTranslation,
      "sort": sort,
    };
  }

  @override
  String toString() => this.toJson().toString();

  ExerciseTree copy(int parentId) {
    ExerciseTree newTree = ExerciseTree();
    newTree.treeId = this.treeId;
    newTree.name = this.name;
    newTree.imageUrl = this.imageUrl;
    newTree.nameTranslation = this.nameTranslation;
    if (parentId != -1) {
      newTree.parentId = parentId;
    }
    newTree.active = this.active;
    newTree.sort = this.sort == null ? 99 : this.sort;

    return newTree;
  }
}
