from utils import model
from django.contrib.postgres.fields import JSONField
from django.db import models
from rest_framework.exceptions import ParseError
from simple_history.models import HistoricalRecords

from apps.system.models import CommonAModel, CommonBModel, Dict, User
from apps.project.models import Project, CertApp
# Create your models here.

class Plan(CommonBModel):
    """
    计划(项目组)
    """
    name = models.CharField('计划名称', max_length = 1000, unique=True)
    month = models.DateField('计划审核月份', null=True, blank=True)

    class Meta:
        verbose_name = '审核计划'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class ContactRecord(CommonBModel):
    """
    联系记录
    """
    project = models.ForeignKey(Project, on_delete=models.CASCADE, verbose_name='所属项目', related_name='contactrecord_project')
    certapp = models.ForeignKey(CertApp, on_delete=models.CASCADE, verbose_name='关联申请', null=True, blank=True, related_name='contactrecord_certapp')
    contact_date = models.DateField('联系时间')
    content = models.TextField('内容')

    class Meta:
        verbose_name = '联系记录'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.content


class Member(CommonAModel):
    """
    业务审核成员
    """
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='成员', related_name='member_user')
    is_accepted = models.BooleanField('是否接受', null=True, default=False)
    certapp = models.ForeignKey(CertApp, on_delete=models.CASCADE, verbose_name='参与申请', related_name='member_certapp')
    man_days = models.DecimalField('人日数', max_digits=4, decimal_places=2, default=0)
    days = models.DecimalField('审核天数', max_digits=4, decimal_places=2, default=0)
    identity = models.ForeignKey(Dict, on_delete=models.SET_NULL, null=True, blank=True, verbose_name='组内身份', related_name='member_identity')
    is_leader = models.BooleanField('是否组长', default=False)
    class Meta:
        verbose_name = '审核组成员'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.member.name
    

