# coding=utf-8

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

from apps.foundation.models import Chapter

class KnowledgeBase(models.Model):
    chapter = models.ForeignKey(Chapter, verbose_name=u"章节", on_delete=models.PROTECT)
    name = models.CharField(max_length=200, verbose_name=u"名称")
    feature = models.TextField(verbose_name=u"识别特征")
    desc = models.TextField(verbose_name=u"备注", null=True, blank=True)
    create_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'录入人',related_name='knowledge_base_user', 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)

    class Meta:
        db_table = "knowledge_base"
        ordering = ['-id']
        verbose_name = u"知识管理"
        default_permissions = ()

class KnowledgeBaseFeedback(models.Model):
    NAME = 1
    FEATURE = 2
    IMG = 3
    OTHER = 4
    TYPE_CHOICES = (
        (NAME, u'名称错误'),
        (FEATURE, u'特征错误'),
        (IMG, u'图片错误'),
        (OTHER, u'其它'),
    )
    TYPE_JSON = [{'id': item[0], 'value': item[1]} for item in TYPE_CHOICES]

    UNTREATED = 1
    PROCESSED = 2
    STATUS_CHOICES = (
        (UNTREATED, u'未处理'),
        (PROCESSED, u'已处理'),
    )
    STATUS_JSON = [{'id': item[0], 'value': item[1]} for item in STATUS_CHOICES]

    main = models.ForeignKey(KnowledgeBase, verbose_name=u"知识", on_delete=models.PROTECT)
    type = models.PositiveSmallIntegerField(choices=TYPE_CHOICES, verbose_name=u"错误类型")
    desc = models.TextField(verbose_name=u"错误描述", null=True, blank=True)
    create_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'反馈人', editable=False, on_delete=models.PROTECT, related_name='knowledge_base_feedback_create_usr_id')
    create_time = models.DateTimeField(verbose_name=u"反馈时间", default=timezone.now, editable=False)
    status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name=u'处理状态', default=UNTREATED)
    process_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u"处理人", on_delete=models.PROTECT, null=True, related_name='knowledge_base_feedback_process_usr_id')
    process_time = models.DateTimeField(verbose_name=u'处理时间', null=True)

    class Meta:
        db_table = "knowledge_base_feedback"
        ordering = ['-id']
        verbose_name = u"错误反馈"
        default_permissions = ()
