/*
 * @Author: wangyang 1147192855@qq.com
 * @Date: 2022-07-18 13:55:30
 * @LastEditors: wangyang 1147192855@qq.com
 * @LastEditTime: 2022-07-20 21:02:36
 * @FilePath: \marking_app\lib\common\model\marking\markingItem.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:json_annotation/json_annotation.dart';
import 'package:marking_app/utils/index.dart';

part 'marking_item.g.dart';

@JsonSerializable(checked: true)
class MarkingItem extends Object {
  @JsonKey(name: 'markingUserId')
  int markingUserId;

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

  @JsonKey(name: 'isSchoolAssign')
  bool isSchoolAssign;

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

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

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

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

  @JsonKey(name: 'isFinish')
  bool isFinish;

  // 完成比例
  @JsonKey(name: 'completionRate')
  double completionRate;

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

  MarkingItem(this.examSubjectId, this.isFinish, this.markingUserId, this.examName, this.subjectId, this.finishCount,
      this.totalCount,
      {this.isSchoolAssign = false, this.completionRate = 0, this.completionRateStr = '0.0'}) {
    if (totalCount != 0) {
      completionRate = finishCount / totalCount;
      completionRateStr = doubleToStringAsFixed((completionRate * 100));
    }
  }

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

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