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

import 'game.dart' as game;

class SportIndex{

  int duration;
  int durationTarget;
  int consume;
  int beyond;
  String inspire;
  game.GameInfoData lastGame;
  List<game.GameInfoData> games;
  RankInfo rank;

  SportIndex(
      {this.duration, this.durationTarget, this.consume, this.beyond, this.inspire, this.lastGame});

  SportIndex.fromJson(Map<String, dynamic> json) {
    duration = json['duration'];
    durationTarget = json['duration_target'];
    consume = json['consume'];
    beyond = json['beyond'];
    inspire = json['inspire'];
    lastGame = json['last_game'] != null
        ? new game.GameInfoData.fromJson(json['last_game'])
        : null;
    rank = json['rank'] != null ? new RankInfo.fromJson(json['rank']) : null;
    if (json['games'] != null) {
      games = new List<game.GameInfoData>();
      json['games'].forEach((v) {
        games.add(new game.GameInfoData.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['duration'] = this.duration;
    data['duration_target'] = this.durationTarget;
    data['consume'] = this.consume;
    data['beyond'] = this.beyond;
    data['inspire'] = this.inspire;
    if (this.lastGame != null) {
      data['last_game'] = this.lastGame.toJson();
    }
    return data;
  }
}
class RankInfo {
  Rank rank;
  User user;
  List<User> records;

  RankInfo({this.rank, this.user, this.records});

  RankInfo.fromJson(Map<String, dynamic> json) {
    rank = json['rank'] != null ? new Rank.fromJson(json['rank']) : null;
    user = json['user'] != null ? new User.fromJson(json['user']) : null;
    if (json['records'] != null) {
      records = new List<User>();
      json['records'].forEach((v) {
        records.add(new User.fromJson(v));
      });
    }
  }

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

class Rank {
  int id;
  String name;
  int isGame;
  int isSport;
  int gameId;
  String introduce;
  int userCountMax;
  String rateBegin;
  String rateEnd;

  Rank(
      {this.id,
        this.name,
        this.isGame,
        this.isSport,
        this.gameId,
        this.introduce,
        this.userCountMax,
        this.rateBegin,
        this.rateEnd});

  Rank.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    isGame = json['is_game'];
    isSport = json['is_sport'];
    gameId = json['game_id'];
    introduce = json['introduce'];
    userCountMax = json['user_count_max'];
    rateBegin = json['rate_begin'];
    rateEnd = json['rate_end'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['name'] = this.name;
    data['is_game'] = this.isGame;
    data['is_sport'] = this.isSport;
    data['game_id'] = this.gameId;
    data['introduce'] = this.introduce;
    data['user_count_max'] = this.userCountMax;
    data['rate_begin'] = this.rateBegin;
    data['rate_end'] = this.rateEnd;
    return data;
  }
}