import 'package:aitrainer_app/model/result.dart';
import 'package:flutter_form_bloc/flutter_form_bloc.dart';

class ExerciseResult {
  int exerciseResultId;
  int customerId;
  int exerciseId;
  int exercisePlanId;
  String resultType;
  double value;
  DateTime dateFrom;
  DateTime dateTo;

  ResultExt resultExtension;

  ExerciseResult();

  Map<String, dynamic> toJson() {
    String formattedDateTo;
    if (dateTo != null) {
      formattedDateTo = DateFormat('yyyy-MM-dd HH:mm').format(dateTo);
    }

    return {
      "customerId": customerId,
      "exerciseId": exerciseId,
      "exercisePlanId": exercisePlanId,
      "resultType": resultType,
      "value": value,
      "dateFrom": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateFrom),
      "dateTo": formattedDateTo,
    };
  }

  ExerciseResult.fromJson(Map json) {
    this.exerciseResultId = json['exerciseResultId'];
    this.exerciseId = json['exerciseId'];
    this.exercisePlanId = json['exercisePlanId'];
    this.customerId = json['customerId'];
    this.resultType = json['resultType'];
    this.value = json["value"];
    this.dateFrom = DateTime.parse(json['dateFrom']);
    this.dateTo = DateTime.parse(json['dateTo']);
    this.resultExtension = ResultExt(itemString: this.resultType);
  }
}