from django.db import models
from apps.system.models import CommonAModel, File
# Create your models here.
class Standard(CommonAModel):
    """
    标准
    """
    number = models.CharField('标准编号', max_length=100)
    name = models.CharField('标准名称', max_length=100)
    enabled = models.BooleanField('是否启用', default=True)
    file = models.ForeignKey(File, verbose_name='文件', null=True, blank=True, on_delete=models.CASCADE)

    class Meta:
        verbose_name = '标准库'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.number + '-' + self.name

class TestItem(CommonAModel):
    """
    检验项目
    """
    name = models.CharField('名称', max_length=100)
    standard = models.ForeignKey(Standard, verbose_name='关联标准', on_delete=models.CASCADE)
    term_number = models.CharField('条款号', max_length=100)

    class Meta:
        verbose_name = '检验项目'
        verbose_name_plural = verbose_name

class AnalysisItem(CommonAModel):
    """
    检验分析项
    """
    name = models.CharField('名称', max_length=100)
    testitem = models.ForeignKey(TestItem, on_delete=models.CASCADE, verbose_name='关联检验项目')
    rules =models.JSONField('判定规则', default=list)

    class Meta:
        verbose_name = '检验分析项'