import 'package:json_annotation/json_annotation.dart';
import 'package:marking_app/utils/index.dart';

part 'report_home_model.g.dart';

@JsonSerializable(checked: true)
class ReportHomeModel extends Object {
  @JsonKey(name: 'ExamData')
  ExamData examData;

  @JsonKey(name: 'ExamSubjectDatas')
  List<ExamSubjectDatas> examSubjectDatas;

  ReportHomeModel(
    this.examData,
    this.examSubjectDatas,
  );

  factory ReportHomeModel.fromJson(Map<String, dynamic> srcJson) => _$ReportHomeModelFromJson(srcJson);

  Map<String, dynamic> toJson() => _$ReportHomeModelToJson(this);
}

@JsonSerializable()
class ExamData extends Object {
  @JsonKey(name: 'ExamId')
  int examId;

  @JsonKey(name: 'ExamName')
  String examName;

  @JsonKey(name: 'ExamType')
  int examType;

  @JsonKey(name: 'ExamTypeName')
  String examTypeName;

  @JsonKey(name: 'Grade')
  String grade;

  @JsonKey(name: 'Subjects')
  String subjects;

  @JsonKey(name: 'AverageScore')
  double averageScore;

  @JsonKey(name: 'TotalScore')
  double totalScore;

  @JsonKey(name: 'TagComparisonList')
  List<TagComparisonList> tagComparisonList;

  @JsonKey(name: 'StartTime')
  String startTime;

  ExamData(
    this.examId,
    this.examName,
    this.examType,
    this.examTypeName,
    this.grade,
    this.subjects,
    this.averageScore,
    this.totalScore,
    this.tagComparisonList,
    this.startTime,
  );

  factory ExamData.fromJson(Map<String, dynamic> srcJson) => _$ExamDataFromJson(srcJson);

  Map<String, dynamic> toJson() => _$ExamDataToJson(this);
}

@JsonSerializable()
class TagComparisonList extends Object {
  @JsonKey(name: 'Name')
  String name;

  @JsonKey(name: 'Count')
  double count;

  TagComparisonList(
    this.name,
    this.count,
  );

  factory TagComparisonList.fromJson(Map<String, dynamic> srcJson) => _$TagComparisonListFromJson(srcJson);

  Map<String, dynamic> toJson() => _$TagComparisonListToJson(this);
}

@JsonSerializable()
class ExamSubjectDatas extends Object {
  @JsonKey(name: 'SubjectId')
  int subjectId;

  @JsonKey(name: 'SubjectName')
  String subjectName;

  @JsonKey(name: 'AverageScore')
  double averageScore;

  @JsonKey(name: 'TotalScore')
  double totalScore;

  @JsonKey(name: 'PassRate')
  double passRate;

  @JsonKey(name: 'passPercent')
  double passPercent;

  @JsonKey(name: 'averagePercent')
  double averagePercent;

  @JsonKey(name: 'AverageScoreStr')
  String averageScoreStr;

  @JsonKey(name: 'TotalScoreStr')
  String totalScoreStr;

  @JsonKey(name: 'PassRateStr')
  String passRateStr;

  ExamSubjectDatas(
    this.subjectId,
    this.subjectName,
    this.averageScore,
    this.totalScore,
    this.passRate, {
    this.averageScoreStr = '',
    this.totalScoreStr = '',
    this.passRateStr = '',
    this.passPercent = 0,
    this.averagePercent = 0,
  }) {
    averageScoreStr = doubleToStringAsFixed(averageScore);
    totalScoreStr = doubleToStringAsFixed(totalScore);
    passRateStr = doubleToStringAsFixed(passRate);
    passPercent = passRate/100;
    averagePercent = averageScore/totalScore;
  }

  factory ExamSubjectDatas.fromJson(Map<String, dynamic> srcJson) => _$ExamSubjectDatasFromJson(srcJson);

  Map<String, dynamic> toJson() => _$ExamSubjectDatasToJson(this);
}
