import 'package:json_annotation/json_annotation.dart';
import 'package:marking_app/common/model/job/job_report_model.dart';

part 'job_data_report.g.dart';

@JsonSerializable()
class JobDataReport extends Object {
  @JsonKey(name: 'jobId')
  int jobId;

  @JsonKey(name: 'jobName')
  String jobName;

  @JsonKey(name: 'gradeName')
  String gradeName;

  @JsonKey(name: 'className')
  String? className;

  @JsonKey(name: 'validCount')
  int validCount;

  @JsonKey(name: 'noAnswerCount')
  int noAnswerCount;

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

  @JsonKey(name: 'kgQuestionCount')
  int kgQuestionCount;

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

  @JsonKey(name: 'zgQuestionCount')
  int zgQuestionCount;

  bool sortType; // true 默认排序 ； false 未提交置顶
  bool sortLevel;
  bool hasUnrated;//有未批阅

  @JsonKey(name: 'studentDetails')
  List<StudentDetails> studentDetails;

  @JsonKey(name: 'kgReport')
  KgReport kgReport;

  @JsonKey(name: 'zgReport')
  ZgReport zgReport;

  JobDataReport(this.jobId, this.jobName, this.gradeName, this.className, this.validCount, this.noAnswerCount,
      this.kgValidRate, this.kgQuestionCount, this.zgValidRate, this.zgQuestionCount, this.studentDetails,  this.kgReport,
      this.zgReport,
  [this.sortType = true,this.sortLevel = false,this.hasUnrated = false]) {

    this.studentDetails.sort((a, b) {
      int num1 = a.kgValidRate + a.zgValidRate;
      int num2 = b.kgValidRate + b.zgValidRate;
      return num2.compareTo(num1);
    });
  }

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

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

@JsonSerializable()
class StudentDetails extends Object {
  @JsonKey(name: 'studentId')
  int? studentId;

  @JsonKey(name: 'studentName')
  String? studentName;

  @JsonKey(name: 'kgValidCount')
  int kgValidCount;

  @JsonKey(name: 'kgValidRate')
  int kgValidRate;

  @JsonKey(name: 'zgValidCount')
  int zgValidCount;

  @JsonKey(name: 'zgValidRate')
  int zgValidRate;

  @JsonKey(name: 'kgDetails')
  List<KgDetails> kgDetails;

  @JsonKey(name: 'zgDetails')
  List<KgDetails> zgDetails;

  @JsonKey(name: 'readLevel')
  int? readLevel;

  @JsonKey(name: 'kgError')
  int kgError;

  @JsonKey(name: 'zgError')
  int zgError;

  @JsonKey(name: 'kgCorrect')
  int kgCorrect;

  @JsonKey(name: 'zgCorrect')
  int zgCorrect;

  @JsonKey(name: 'unrated')
  int unrated;

  //全部未做
  @JsonKey(name: 'allNotDone')
  bool allNotDone;

  StudentDetails(
    this.studentId,
    this.studentName,
    this.kgValidCount,
    this.kgValidRate,
    this.zgValidCount,
    this.zgValidRate,
    this.kgDetails,
    this.zgDetails,
    this.readLevel,
      [this.kgError = 0,this.kgCorrect = 0,this.zgCorrect = 0,this.zgError = 0,this.unrated = 0,this.allNotDone = false]
  );

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

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

@JsonSerializable()
class KgDetails extends Object {
  @JsonKey(name: 'questionNo')
  String questionNo;

  @JsonKey(name: 'questionId')
  int questionId;

  @JsonKey(name: 'partName')
  String partName;

  @JsonKey(name: 'state')
  int state;

  @JsonKey(name: 'studentAnswer')
  String? studentAnswer;

  @JsonKey(name: 'questionAnswer')
  String? questionAnswer;

  @JsonKey(name: 'useTime')
  int? useTime;

  @JsonKey(name: 'annotateAnswers')
  String? annotateAnswers;

  @JsonKey(name: 'score')
  double? score;

  KgDetails(
    this.questionNo,
    this.questionId,
    this.partName,
    this.state,
    this.studentAnswer,
    this.questionAnswer,
    this.useTime,
    this.annotateAnswers,
    this.score,
  );

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

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