import 'package:json_annotation/json_annotation.dart';

import 'job_report_knowledge_model.dart';

part 'job_report_model.g.dart';

@JsonSerializable()
class JobReportModel extends Object {
  @JsonKey(name: 'studentCount')
  int studentCount;

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

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

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

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

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

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

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

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

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

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

  @JsonKey(name: 'knowledgeInfos')
  List<KnowledgeInfos> knowledgeInfos;

  @JsonKey(name: 'questionAnswerInfos')
  List<QuestionAnswerInfos> questionAnswerInfos;

  @JsonKey(name: 'studentAnswerInfos')
  List<StudentAnswerInfos> studentAnswerInfos;

  @JsonKey(name: 'overallInfos')
  Map<String,overallInfo> overallInfos;

  @JsonKey(name: 'overallTitles')
  List<OverallTitles> overallTitles;

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

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

  @JsonKey(name: 'noAnswerStudentNames')
  List<String> noAnswerStudentNames;

  @JsonKey(name: 'allCorrectStudentNames')
  List<String> allCorrectStudentNames;

  @JsonKey(name: 'validStudentNames')
  List<String> validStudentNames;

  @JsonKey(name: 'noAnswerStudents')
  List<AnswerOkStudents>? noAnswerStudents;

  @JsonKey(name: 'allCorrectStudents')
  List<AnswerOkStudents>? allCorrectStudents;

  @JsonKey(name: 'validStudents')
  List<AnswerOkStudents>? validStudents;

  // 前端自定义 -- 全对学生
  @JsonKey(name: 'allpairsStudents')
  List<StudentAnswerInfos>? allpairsStudents;

  // 前端自定义 -- 及格学生
  @JsonKey(name: 'passStudents')
  List<StudentAnswerInfos>? passStudents;

  // 前端自定义 -- 不及格学生
  @JsonKey(name: 'disqualifiedStudents')
  List<StudentAnswerInfos>? disqualifiedStudents;

  // 前端自定义 -- 未做学生
  @JsonKey(name: 'notdoneStudents')
  List<StudentAnswerInfos>? notdoneStudents;

  JobReportModel(
    this.studentCount,
    this.finishRate,
    this.correctRate,
    this.errorRate,
    this.validCount,
    this.allCorrect,
    this.passCount,
    this.failCount,
    this.noAnswerCount,
    this.score,
    this.scoreTitle,
    this.knowledgeInfos,
    this.questionAnswerInfos,
    this.studentAnswerInfos,
    this.overallInfos,
    this.overallTitles,
      this.kgReport,
      this.zgReport,
      this.noAnswerStudentNames,
      this.allCorrectStudentNames,
      this.validStudentNames,
      this.noAnswerStudents,
      this.allCorrectStudents,
      this.validStudents,
      [
    this.allpairsStudents,
    this.passStudents,
    this.disqualifiedStudents,
    this.notdoneStudents,
  ]) {
    this.allpairsStudents = [];
    this.passStudents = [];
    this.disqualifiedStudents = [];
    this.notdoneStudents = [];
    // 赋值数据
    studentAnswerInfos.forEach((item) {
      if (item.correctRate == 100 && item.noAnswerCount == 0) {
        // 全对
        allpairsStudents?.add(item);
      }
      if (item.correctRate >= 60 && item.correctRate < 100) {
        // 及格
        passStudents?.add(item);
      }
      if (item.correctRate >= 0 && item.correctRate < 60) {
        // 不及格
        disqualifiedStudents?.add(item);
      }
      if (questionAnswerInfos.length == item.noAnswerCount) {
        // 未做
        notdoneStudents?.add(item);
      }
    });
  }

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

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

@JsonSerializable()
class KnowledgeInfos extends Object {
  @JsonKey(name: 'knowledgeId')
  int knowledgeId;

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

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

  @JsonKey(name: 'details')
  List<JobReportKnowledgeModel>? details;

  KnowledgeInfos(
    this.knowledgeId,
    this.knowledgeName,
    this.rate,
  );

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

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

@JsonSerializable()
class QuestionAnswerInfos extends Object {
  @JsonKey(name: 'questionId')
  int questionId;

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

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

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

  @JsonKey(name: 'finishInfos')
  List<FinishInfos> finishInfos;

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

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

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

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

  QuestionAnswerInfos(
    this.questionId,
    this.questionType,
    this.partName,
    this.questionNo,
    this.finishInfos,
    this.correctRate,
    this.errorRate,
    this.noAnswerRate,
    this.questionPicture,
  );

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

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

@JsonSerializable()
class FinishInfos extends Object {
  @JsonKey(name: 'title')
  String title;

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

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

  FinishInfos(
    this.title,
    this.finishCount,
    this.correctRate,
  );

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

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

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

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

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

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

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

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

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

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

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

  StudentAnswerInfos(
    this.studentId,
    this.studentName,
    this.useTime,
    this.correctRate,
    this.finishRate,
    this.noAnswerCount,
    this.ranking,
    this.score,
    this.scoreTitle,
  );

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

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

@JsonSerializable()
class OverallTitles extends Object {
  @JsonKey(name: 'title')
  String title;

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

  @JsonKey(name: 'studentNames')
  List<String> studentNames;


  OverallTitles(
    this.title,
    this.count,
    this.studentNames,
  );

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

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

@JsonSerializable()
class KgReport extends Object {

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

  @JsonKey(name: 'details')
  List<Details> details;

  KgReport(this.correctRate,this.details,);

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

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

}

@JsonSerializable()
class ZgReport extends Object {

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

  @JsonKey(name: 'details')
  List<Details> details;

  ZgReport(this.correctRate,this.details,);

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

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

}

@JsonSerializable()
class Details extends Object {

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

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

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

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

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

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

/*  @JsonKey(name: 'validStudentNames')
  List<String> validStudentNames;*/

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

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

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

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

  @JsonKey(name: 'priorityStudentNames')
  List<String> priorityStudentNames;

  @JsonKey(name: 'answerNgStudentNames')
  List<String> answerNgStudentNames;

  @JsonKey(name: 'noAnswerStudentNames')
  List<String> noAnswerStudentNames;

  @JsonKey(name: 'answerOkStudentNames')
  List<String> answerOkStudentNames;

  @JsonKey(name: 'noAnswerStudents')
  List<AnswerOkStudents>? noAnswerStudents;

  @JsonKey(name: 'answerOkStudents')
  List<AnswerOkStudents>? answerOkStudents;

  @JsonKey(name: 'answerNgStudents')
  List<AnswerOkStudents>? answerNgStudents;

  @JsonKey(name: 'priorityStudents')
  List<AnswerOkStudents>? priorityStudents;

  Details(this.questionNo,this.questionId,this.partName,this.questionType,this.validRate,  this.noAnswerStudents,
      this.answerOkStudents,this.answerNgStudents,this.priorityStudents,
      this.validCount,this.correctRate,this.questionAnswer,this.questionPicture,this.priorityGeneral,
      this.priorityStudentNames,this.answerNgStudentNames,this.noAnswerStudentNames,this.answerOkStudentNames);

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

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

}


@JsonSerializable()
class overallInfo extends Object {

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

  @JsonKey(name: 'students')
  List<AnswerOkStudents> students;

  overallInfo(this.count,this.students,);

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

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

}

@JsonSerializable()
class AnswerOkStudents extends Object {

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

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

  AnswerOkStudents(this.id,this.name,);

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

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

}
