

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

class SportStep {
  List<Record> records;
  Sum sum;

  SportStep({this.records, this.sum});

  SportStep.fromJson(Map<String, dynamic> json) {
    if (json['records'] != null) {
      records = new List<Record>();
      json['records'].forEach((v) {
        records.add(new Record.fromJson(v));
      });
    }
    sum = json['sum'] != null ? new Sum.fromJson(json['sum']) : null;
  }

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

class Record {
  int id;
  int userId;
  int step;
  int distance;
  int stepGame;
  int stepDaily;
  String createdAt;
  int year;
  int month;

  Record({this.id, this.userId, this.step, this.distance, this.stepGame, this.stepDaily, this.createdAt});

  Record.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    userId = json['user_id'];
    step = json['step'];
    distance = json['distance'];
    stepGame = json['step_game'];
    stepDaily = json['step_daily'];
    createdAt = json['created_at'];
    year = json['year'];
    month = json['month'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['user_id'] = this.userId;
    data['step'] = this.step;
    data['distance'] = this.distance;
    data['step_game'] = this.stepGame;
    data['step_daily'] = this.stepDaily;
    data['created_at'] = this.createdAt;
    return data;
  }
}

class Sum {
  int stepDayAvg;
  int distance;
  int step;
  int stepDaily;
  int stepGame;
  double stepRate;
  double stepRateMax;

  Sum({this.stepDayAvg, this.distance, this.step, this.stepDaily, this.stepGame, this.stepRate, this.stepRateMax});

  Sum.fromJson(Map<String, dynamic> json) {
    stepDayAvg = json['step_day_avg'];
    distance = json['distance'];
    step = json['step'];
    stepDaily = json['step_daily'];
    stepGame = json['step_game'];
    stepRate = Converter.toDouble(json['step_rate']);
    stepRateMax =  Converter.toDouble(json['step_rate_max']);
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['step_day_avg'] = this.stepDayAvg;
    data['distance'] = this.distance;
    data['step'] = this.step;
    data['step_daily'] = this.stepDaily;
    data['step_game'] = this.stepGame;
    data['step_rate'] = this.stepRate;
    data['step_rate_max'] = this.stepRateMax;
    return data;
  }
}
