from django.db import models
from utils.model import SoftModel, BaseModel
from apps.system.models import CommonAModel, CommonBModel, User
from simple_history.models import HistoricalRecords
# Create your models here.

class Expert(CommonBModel):
    
    gender_choices = (
        ('男', '男'),
        ('女', '女'),
    )

    user = models.OneToOneField(User, on_delete=models.CASCADE, null=True, blank=True, verbose_name="关联账户", related_name="expert_user")
    name = models.CharField(verbose_name="姓名", max_length=100)
    gender = models.CharField(verbose_name="性别",choices=gender_choices, default='男', max_length=10)
    idnumber = models.CharField(verbose_name="身份证号", max_length=40)
    paddress = models.TextField(verbose_name="通讯地址")
    photo = models.CharField(verbose_name="证件照", max_length=100, null=True, blank=True)
    history = HistoricalRecords()

    class Meta:
        verbose_name = '专家信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class WorkExperience(CommonAModel):
    
    name = models.CharField(verbose_name="单位名", max_length=100)
    start_date = models.DateField(verbose_name="开始日期")
    post = models.CharField(verbose_name="职务/岗位", max_length=100)
    expert = models.ForeignKey(Expert, on_delete=models.CASCADE, verbose_name="所属专家", related_name="workexperience_expert")
    class Meta:
        verbose_name = '专家工作经历'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class Project(CommonAModel):
    
    name = models.CharField(verbose_name="名称", max_length=100)
    number = models.CharField(verbose_name="项目编号", max_length=100)
    start_date = models.DateField(verbose_name="开始日期")
    content = models.TextField(verbose_name="主要工作内容")
    expert = models.ForeignKey(Expert, on_delete=models.CASCADE, verbose_name="所属专家", related_name="project_expert")
    class Meta:
        verbose_name = '专家项目'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class Paper(CommonAModel):
    
    name = models.CharField(verbose_name="名称", max_length=100)
    is_leader = models.BooleanField(verbose_name="是否第一作者", default=True)
    publish_date = models.DateField(verbose_name="发表日期")
    expert = models.ForeignKey(Expert, on_delete=models.CASCADE, verbose_name="所属专家", related_name="paper_expert")
    class Meta:
        verbose_name = '专家论文/著作'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Award(CommonAModel):

    level_choices = (
        ('省部级', '省部级'),
    )

    name = models.CharField(verbose_name="名称", max_length=100)
    level = models.CharField(verbose_name="级别", choices=level_choices, max_length=60)
    issue_date = models.DateField(verbose_name="颁发日期")
    expert = models.ForeignKey(Expert, on_delete=models.CASCADE, verbose_name="所属专家", related_name="award_expert")
    class Meta:
        verbose_name = '专家获奖/荣誉'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name