import 'dict_item.model.dart';

class DictTypeModel {
  DictTypeModel({
    required this.id,
    required this.createdAt,
    required this.updatedAt,
    required this.creator,
    required this.updater,
    required this.name,
    required this.code,
    required this.status,
    required this.remark,
    required this.dictItems,
  });

  final int? id;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final String? creator;
  final String? updater;
  final String? name;
  final String? code;
  final int? status;
  final String? remark;
  final List<DictItemModel> dictItems;

  factory DictTypeModel.fromJson(Map<String, dynamic> json) {
    return DictTypeModel(
      id: json["id"],
      createdAt: DateTime.tryParse(json["createdAt"] ?? ""),
      updatedAt: DateTime.tryParse(json["updatedAt"] ?? ""),
      creator: json["creator"],
      updater: json["updater"],
      name: json["name"],
      code: json["code"],
      status: json["status"],
      remark: json["remark"],
      dictItems: json["dictItems"] == null
          ? []
          : List<DictItemModel>.from(
              json["dictItems"]!.map((x) => DictItemModel.fromJson(x))),
    );
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "createdAt": createdAt?.toIso8601String(),
        "updatedAt": updatedAt?.toIso8601String(),
        "creator": creator,
        "updater": updater,
        "name": name,
        "code": code,
        "status": status,
        "remark": remark,
        "dictItems": dictItems.map((x) => x.toJson()).toList(),
      };
}
