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

class AchievementInfo {
  int result;
  int code;
  String msg;
  AchievementInfoData data;

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

  AchievementInfo.fromJson(Map<String, dynamic> json) {
    result = json['result'];
    code = json['code'];
    msg = json['msg'];
    data = json['data'] != null ? new AchievementInfoData.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 AchievementInfoData {
//  List<Achievement> achievements;
//  List<Achievement> remainAchievements;
//  List<Levels> levels;
//  User user;
//  Extra extra;
//
//  AchievementInfoData({this.achievements, this.remainAchievements, this.levels, this.user, this.extra});
//
//  AchievementInfoData.fromJson(Map<String, dynamic> json) {
//    if (json['achievements'] != null) {
//      achievements = new List<Achievement>();
//      json['achievements'].forEach((v) {
//        achievements.add(new Achievement.fromJson(v));
//      });
//    }
//    if (json['remain_achievements'] != null) {
//      remainAchievements = new List<Achievement>();
//      json['remain_achievements'].forEach((v) {
//        remainAchievements.add(new Achievement.fromJson(v));
//      });
//    }
//    if (json['levels'] != null) {
//      levels = new List<Levels>();
//      json['levels'].forEach((v) {
//        levels.add(new Levels.fromJson(v));
//      });
//    }
//    user = json['user'] != null ? new User.fromJson(json['user']) : null;
//    extra = json['extra'] != null ? new Extra.fromJson(json['extra']) : null;
//  }
//
//  Map<String, dynamic> toJson() {
//    final Map<String, dynamic> data = new Map<String, dynamic>();
//    if (this.achievements != null) {
//      data['achievements'] = this.achievements.map((v) => v.toJson()).toList();
//    }
//    if (this.remainAchievements != null) {
//      data['remain_achievements'] = this.remainAchievements.map((v) => v.toJson()).toList();
//    }
//    if (this.levels != null) {
//      data['levels'] = this.levels.map((v) => v.toJson()).toList();
//    }
//    if (this.user != null) {
//      data['user'] = this.user.toJson();
//    }
//    if (this.extra != null) {
//      data['extra'] = this.extra.toJson();
//    }
//    return data;
//  }
//}

//class Levels {
//  int id;
//  int level;
//  int score;
//  String logo;
//
//  Levels({this.id, this.level, this.score, this.logo});
//
//  Levels.fromJson(Map<String, dynamic> json) {
//    id = json['id'];
//    level = json['level'];
//    score = json['score'];
//    logo = json['logo'];
//  }
//
//  Map<String, dynamic> toJson() {
//    final Map<String, dynamic> data = new Map<String, dynamic>();
//    data['id'] = this.id;
//    data['level'] = this.level;
//    data['score'] = this.score;
//    data['logo'] = this.logo;
//    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;
//  SportRecordSum sportRecordSum;
//  List<Achievement> achievements;
//  Levels levelInfo;
//
//  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,
//      this.sportRecordSum,
//      this.achievements,
//      this.levelInfo});
//
//  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 = json['gender'];
//    age = json['age'];
//    avatar = json['avatar'];
//    province = json['province'];
//    city = json['city'];
//    district = json['district'];
//    sportRecordSum = json['sport_record_sum'] != null ? new SportRecordSum.fromJson(json['sport_record_sum']) : null;
//    if (json['achievements'] != null) {
//      achievements = new List<Achievement>();
//      json['achievements'].forEach((v) {
//        achievements.add(new Achievement.fromJson(v));
//      });
//    }
//
//    levelInfo = json['level_info'] != null ? new Levels.fromJson(json['level_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.sportRecordSum != null) {
//      data['sport_record_sum'] = this.sportRecordSum.toJson();
//    }
//    if (this.achievements != null) {
//      data['achievements'] = this.achievements.map((v) => v.toJson()).toList();
//    }
//    return data;
//  }
//}
//
//class SportRecordSum {
//  int id;
//  int userId;
//  int consume;
//  int duration;
//  int jumpCount;
//  int crouchCount;
//
//  SportRecordSum({this.id, this.userId, this.consume, this.duration, this.jumpCount, this.crouchCount});
//
//  SportRecordSum.fromJson(Map<String, dynamic> json) {
//    id = json['id'];
//    userId = json['user_id'];
//    consume = json['consume'];
//    duration = json['duration'];
//    jumpCount = json['jump_count'];
//    crouchCount = json['crouch_count'];
//  }
//
//  Map<String, dynamic> toJson() {
//    final Map<String, dynamic> data = new Map<String, dynamic>();
//    data['id'] = this.id;
//    data['user_id'] = this.userId;
//    data['consume'] = this.consume;
//    data['duration'] = this.duration;
//    data['jump_count'] = this.jumpCount;
//    data['crouch_count'] = this.crouchCount;
//    return data;
//  }
//}

//class Achievements {
//  int id;
//  String name;
//  String logo;
//  int conditionDuration;
//  int sort;
//  int seriesId;
//  int rewardScore;
//  Null position;
//  String createdAt;
//
//  Achievements(
//      {this.id,
//        this.name,
//        this.logo,
//        this.conditionDuration,
//        this.sort,
//        this.seriesId,
//        this.rewardScore,
//        this.position,
//        this.createdAt});
//
//  Achievements.fromJson(Map<String, dynamic> json) {
//    id = json['id'];
//    name = json['name'];
//    logo = json['logo'];
//    conditionDuration = json['condition_duration'];
//    sort = json['sort'];
//    seriesId = json['series_id'];
//    rewardScore = json['reward_score'];
//    position = json['position'];
//    createdAt = json['created_at'];
//  }
//
//  Map<String, dynamic> toJson() {
//    final Map<String, dynamic> data = new Map<String, dynamic>();
//    data['id'] = this.id;
//    data['name'] = this.name;
//    data['logo'] = this.logo;
//    data['condition_duration'] = this.conditionDuration;
//    data['sort'] = this.sort;
//    data['series_id'] = this.seriesId;
//    data['reward_score'] = this.rewardScore;
//    data['position'] = this.position;
//    data['created_at'] = this.createdAt;
//    return data;
//  }
//}

class AchievementInfoData {
  Level level;
  int score;
  int exp;
  int nextLevelExp;
  int allAchievementCount;
  int getAchievementCount;
  double getAchievementPercent;
  List<Achievement> getAchievementList;
  List<Achievement> remainAchievementList;

  AchievementInfoData(
      {this.level,
        this.score,
        this.exp,
        this.nextLevelExp,
        this.allAchievementCount,
        this.getAchievementCount,
        this.getAchievementPercent,
        this.getAchievementList,
        this.remainAchievementList});

  AchievementInfoData.fromJson(Map<String, dynamic> json) {
    level = json['level'] != null ? new Level.fromJson(json['level']) : null;
    score = json['score'];
    exp = json['exp'];
    nextLevelExp = json['next_level_exp'];
    allAchievementCount = json['all_achievement_count'];
    getAchievementCount = json['get_achievement_count'];
    getAchievementPercent = Converter.toDouble(json['get_achievement_percent']);
    getAchievementList = new List<Achievement>();
    if (json['get_achievement_list'] != null) {
      json['get_achievement_list'].forEach((v) {
        getAchievementList.add(new Achievement.fromJson(v));
      });
    }
    remainAchievementList = new List<Achievement>();
    if (json['remain_achievement_list'] != null) {
      json['remain_achievement_list'].forEach((v) {
        remainAchievementList.add(new Achievement.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.level != null) {
      data['level'] = this.level.toJson();
    }
    data['score'] = this.score;
    data['exp'] = this.exp;
    data['next_level_exp'] = this.nextLevelExp;
    data['all_achievement_count'] = this.allAchievementCount;
    data['get_achievement_count'] = this.getAchievementCount;
    data['get_achievement_percent'] = this.getAchievementPercent;
    if (this.getAchievementList != null) {
      data['get_achievement_list'] =
          this.getAchievementList.map((v) => v.toJson()).toList();
    }
    if (this.remainAchievementList != null) {
      data['remain_achievement_list'] =
          this.remainAchievementList.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class Level {
  int level;
  String logo;

  Level({this.level, this.logo});

  Level.fromJson(Map<String, dynamic> json) {
    level = json['level'];
    logo = json['logo'];
  }

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

class Extra {
  NextLevel nextLevel;
  NextLevel nextAchievement;

  Extra({this.nextLevel, this.nextAchievement});

  Extra.fromJson(Map<String, dynamic> json) {
    nextLevel = json['next_level'] != null ? new NextLevel.fromJson(json['next_level']) : null;
    nextAchievement = json['next_achievement'] != null ? new NextLevel.fromJson(json['next_achievement']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.nextLevel != null) {
      data['next_level'] = this.nextLevel.toJson();
    }
    if (this.nextAchievement != null) {
      data['next_achievement'] = this.nextAchievement.toJson();
    }
    return data;
  }
}

class NextLevel {
  Achievement target;
  int diff;

  NextLevel({this.target, this.diff});

  NextLevel.fromJson(Map<String, dynamic> json) {
    target = json['target'] != null ? new Achievement.fromJson(json['target']) : null;
    diff = json['diff'];
  }

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