import 'package:netrain_flutter_app/douwen/custom/http/base/HttpCode.dart';

/// code : -1
/// msg : "系统繁忙!"
/// data : null
/// timestamp : "2021-07-21 15:29:05"

class IEntity<T> {
  int _code;
  String _msg;
  dynamic _data;
  String _timestamp;

  int get code => _code;
  set code(int code) => _code = code;

  String get msg => _msg;
  set msg(String msg) => _msg = msg;

  dynamic get data => _data;

  String get timestamp => _timestamp;
  set timestamp(String msg) => _timestamp = msg;

  IEntity({int code, String msg, dynamic data, String timestamp}) {
    _code = code;
    _msg = msg;
    _data = data;
    _timestamp = timestamp;
  }

  bool isSuccess(){
    if (code == HttpCode.SUCCESS) {
      return true;
    } else {
      return false;
    }
  }

  IEntity.fromJson(dynamic json) {
    _code = json["code"];
    _msg = json["msg"];
    _data = json["data"];
    _timestamp = json["timestamp"];
  }

  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map["code"] = _code;
    map["msg"] = _msg;
    map["data"] = _data;
    map["timestamp"] = _timestamp;
    return map;
  }
}
