# coding=utf-8

from django.db import models
from django.utils import timezone
from django.conf import settings

from apps.foundation.models import Subject
from apps.examination.examquestion.models import ExamQuestion

class ExamPaper(models.Model):
    MOCK = 1
    FORMAL = 2
    RANDOM = 3
    TYPE_CHOICES = (
        (MOCK, u'模拟试卷'),
        (FORMAL, u'正式试卷'),
        (RANDOM, u'随机试卷'),
    )
    TYPE_JSON = [{'id': item[0], 'value': item[1]} for item in TYPE_CHOICES]

    name = models.CharField(max_length=200, verbose_name=u"名称")
    subject = models.ForeignKey(Subject, verbose_name=u"科目", on_delete=models.PROTECT)
    type = models.PositiveSmallIntegerField(choices=TYPE_CHOICES, verbose_name=u"类型")
    passline = models.IntegerField(verbose_name=u'及格线')
    desc = models.TextField(verbose_name=u"备注", null=True, blank=True)

    single_simple_count = models.IntegerField(verbose_name=u'简单单选题数量', default=0)
    multiple_simple_count = models.IntegerField(verbose_name=u'简单多选题数量', default=0)
    fill_simple_count = models.IntegerField(verbose_name=u'简单填空题数量', default=0)
    judgment_simple_count = models.IntegerField(verbose_name=u'简单判断题数量', default=0)
    single_mid_count = models.IntegerField(verbose_name=u'中等单选题数量', default=0)
    multiple_mid_count = models.IntegerField(verbose_name=u'中等多选题数量', default=0)
    fill_mid_count = models.IntegerField(verbose_name=u'中等填空题数量', default=0)
    judgment_mid_count = models.IntegerField(verbose_name=u'中等判断题数量', default=0)
    single_hard_count = models.IntegerField(verbose_name=u'困难单选题数量', default=0)
    multiple_hard_count = models.IntegerField(verbose_name=u'困难多选题数量', default=0)
    fill_hard_count = models.IntegerField(verbose_name=u'困难填空题数量', default=0)
    judgment_hard_count = models.IntegerField(verbose_name=u'困难判断题数量', default=0)
    single_scores = models.IntegerField(verbose_name=u'单选题单题分数', default=0)
    multiple_scores = models.IntegerField(verbose_name=u'多选题单题分数', default=0)
    fill_scores = models.IntegerField(verbose_name=u'填空题单题分数', default=0)
    judgment_scores = models.IntegerField(verbose_name=u'判断题单题分数', default=0)

    single_total_count = models.IntegerField(verbose_name=u'单选题总数量', default=0, editable=False)
    multiple_total_count = models.IntegerField(verbose_name=u'多选题总数量', default=0, editable=False)
    fill_total_count = models.IntegerField(verbose_name=u'填空题总数量', default=0, editable=False)
    judgment_total_count = models.IntegerField(verbose_name=u'判断题总数量', default=0, editable=False)
    single_total_scores = models.IntegerField(verbose_name=u'单选题总分数', default=0, editable=False)
    multiple_total_scores = models.IntegerField(verbose_name=u'多选题总分数', default=0, editable=False)
    fill_total_scores = models.IntegerField(verbose_name=u'填空题总分数', default=0, editable=False)
    judgment_total_scores = models.IntegerField(verbose_name=u'判断题总分数', default=0, editable=False)
    question_total_count  = models.IntegerField(verbose_name=u'试题总数量', default=0, editable=False)
    question_total_scores = models.IntegerField(verbose_name=u'试题总分数', default=0, editable=False)

    create_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'添加人', editable=False, on_delete=models.PROTECT)
    create_time = models.DateTimeField(verbose_name=u"添加时间", default=timezone.now, editable=False)
    delete = models.BooleanField(verbose_name=u'删除', default=False, editable=False)

    did_count = models.IntegerField(verbose_name=u'做过人数', default=0, editable=False)

    class Meta:
        db_table = "exam_paper"
        ordering = ['-id']
        verbose_name = u"试卷管理"
        default_permissions = ()

class ExamPaperDetail(models.Model):
    main = models.ForeignKey(ExamPaper, verbose_name=u"试卷", on_delete=models.PROTECT)
    question = models.ForeignKey(ExamQuestion, verbose_name=u"试题", on_delete=models.PROTECT)
    order = models.IntegerField(verbose_name=u'序号', editable=False)

    class Meta:
        db_table = "exam_paper_detail"
        ordering = ['order']
        verbose_name = u"试卷明细"
        default_permissions = ()