import 'dart:convert';

import 'package:zhiying_base_widget/dialog/global_dialog/intellect_search_goods_dialog/model/no_goods_dialog_style_model.dart';
import 'package:zhiying_comm/models/base/skip_model.dart';
import 'package:zhiying_comm/util/empty_util.dart';

class MessageNoticeDataModel {
  List<MessageNoticeDataItemModel> list;

  MessageNoticeDataModel({this.list});

  factory MessageNoticeDataModel.fromJson(Map<String, dynamic> json) {
    return MessageNoticeDataModel(
      list: json['list'] != null ? (json['list'] as List).map((i) => MessageNoticeDataItemModel.fromJson(i)).toList() : null,
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.list != null) {
      data['list'] = this.list.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class MessageNoticeDataItemModel extends SkipModel {
  String unread_count;
  String receiver;
  String body;
  String date_time;
  String id;
  String img;
  String main_preview;
  String oid;
  String sender;
  String status;
  String subtitle;
  String title;
  String type;
  List<TransactionBodyItemModel> transactions;

  MessageNoticeDataItemModel({
    this.unread_count,
    this.receiver,
    this.body,
    this.date_time,
    this.id,
    this.img,
    this.main_preview,
    this.oid,
    this.sender,
    this.status,
    this.subtitle,
    this.title,
    this.type,
    this.transactions,
  });

  MessageNoticeDataItemModel.fromJson(Map<String, dynamic> json) {
    super.fromJson(json);
    unread_count = json['unread_count']?.toString();
    receiver = json['receiver']?.toString();
    body = json['body']?.toString();
    date_time = json['date_time']?.toString();
    id = json['id']?.toString();
    img = json['img']?.toString();
    main_preview = json['main_preview']?.toString();
    oid = json['oid']?.toString();
    sender = json['sender']?.toString();
    status = json['status']?.toString();
    subtitle = json['subtitle']?.toString();
    title = json['title']?.toString();
    type = json['type']?.toString();
    transactions = (!EmptyUtil.isEmpty(json['body']) && jsonDecode(json['body']) != null)
        ? (jsonDecode(json['body']) as List).map((e) => TransactionBodyItemModel.fromJson(e)).toList()
        : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = super.toJson();
    data['receiver'] = this.receiver;
    data['body'] = this.body;
    data['date_time'] = this.date_time;
    data['id'] = this.id;
    data['img'] = this.img;
    data['main_preview'] = this.main_preview;
    data['oid'] = this.oid;
    data['sender'] = this.sender;
    data['status'] = this.status;
    data['subtitle'] = this.subtitle;
    data['title'] = this.title;
    data['type'] = this.type;
    if (null != this.transactions) {
      data['transactions'] = this.transactions.map((e) => e.toJson()).toList();
    }
    return data;
  }
}

class TransactionBodyItemModel {
  String data;
  String text;
  String type;

  TransactionBodyItemModel({this.data, this.text, this.type});

  factory TransactionBodyItemModel.fromJson(Map<String, dynamic> json) {
    return TransactionBodyItemModel(
      data: json['data'],
      text: json['text'],
      type: json['type'],
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['data'] = this.data;
    data['text'] = this.text;
    data['type'] = this.type;
    return data;
  }
}
