from django.db import models
from apps.utils.models import BaseModel, CommonADModel, CommonBDModel
# Create your models here.


class Dataset(CommonBDModel):
    name = models.CharField('名称', max_length=100)
    code = models.CharField('标识', max_length=100, default='', blank=True)
    description = models.TextField('描述说明', default='', blank=True)
    sql_query = models.TextField('sql查询语句', default='', blank=True)
    echart_options = models.TextField(default='', blank=True)
    test_param = models.JSONField('测试查询参数', default=dict, blank=True)
    default_param = models.JSONField('默认查询参数', default=dict, blank=True)
    cache_seconds = models.PositiveIntegerField('缓存秒数', default=10, blank=True)
    enabled = models.BooleanField('启用', default=True)


# class Report(CommonBDModel):
#     name = models.CharField('名称', max_length=100)
#     code = models.CharField('标识', max_length=100, default='', blank=True)
#     js_function = models.TextField('数据转化函数', default='', blank=True)
#     datasets = models.ManyToManyField(Dataset, verbose_name='关联数据集', blank=True)
class DatasetRecord(BaseModel):
    """
    数据执行记录
    """
    timex = models.DateTimeField('执行时间', auto_now_add=True)
    dataset = models.ForeignKey(Dataset, on_delete=models.CASCADE, verbose_name='数据集')
    full_sql = models.TextField('完整SQL', null=True, blank=True)
    result = models.JSONField('执行返回', default=dict, blank=True)