import 'package:sport/bean/bind_info.dart';
import 'package:sport/services/Converter.dart';

class LoginInfo {
  int result;
  int code;
  String msg;
  Data data;

  LoginInfo({this.result, this.code, this.msg, this.data});

  LoginInfo.fromJson(Map<String, dynamic> json) {
    result = json['result'];
    code = json['code'];
    msg = json['msg'];
    data = json['data'] != null ? new Data.fromJson(json['data']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['result'] = this.result;
    data['code'] = this.code;
    data['msg'] = this.msg;
    if (this.data != null) {
      data['data'] = this.data.toJson();
    }
    return data;
  }
}

class Data {
  String token;
  User user;
  bool isNew;
  Data({this.token, this.user,this.isNew});

  Data.fromJson(Map<String, dynamic> json) {
    token = json['token'];
    user = json['user'] != null ? new User.fromJson(json['user']) : null;
    isNew = json['is_new'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['token'] = this.token;
    if (this.user != null) {
      data['user'] = this.user.toJson();
    }
    data['is_new'] = this.isNew;
    return data;
  }
}

class User {
  int id;
  String name;
  int sportTargetId;
  int topSubjectId;
  int level;
  int score;
  int isBan;
  int provinceId;
  int cityId;
  int districtId;
  String createdAt;
  int gender;
  int age;
  String avatar;
  String province;
  String city;
  String district;
  BindInfoData bindInfo;

  User(
      {this.id,
        this.name,
        this.sportTargetId,
        this.topSubjectId,
        this.level,
        this.score,
        this.isBan,
        this.provinceId,
        this.cityId,
        this.districtId,
        this.createdAt,
        this.gender,
        this.age,
        this.avatar,
        this.province,
        this.city,
        this.district});

  User.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    sportTargetId = json['sport_target_id'];
    topSubjectId = json['top_subject_id'];
    level = json['level'];
    score = json['score'];
    isBan = json['is_ban'];
    provinceId = json['province_id'];
    cityId = json['city_id'];
    districtId = json['district_id'];
    createdAt = json['created_at'];
    gender = Converter.toInt(json['gender']);
    age =  Converter.toInt(json['age']);
    avatar = json['avatar'];
    province = json['province'];
    city = json['city'];
    district = json['district'];

    bindInfo = json['bind_info'] != null ? new BindInfoData.fromJson(json['bind_info']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['name'] = this.name;
    data['sport_target_id'] = this.sportTargetId;
    data['top_subject_id'] = this.topSubjectId;
    data['level'] = this.level;
    data['score'] = this.score;
    data['is_ban'] = this.isBan;
    data['province_id'] = this.provinceId;
    data['city_id'] = this.cityId;
    data['district_id'] = this.districtId;
    data['created_at'] = this.createdAt;
    data['gender'] = this.gender;
    data['age'] = this.age;
    data['avatar'] = this.avatar;
    data['province'] = this.province;
    data['city'] = this.city;
    data['district'] = this.district;

    if (this.bindInfo != null) {
      data['bind_info'] = this.bindInfo.toJson();
    }
    return data;
  }
}