from django.db import models
from django.utils.translation import gettext_lazy as _

# Create your models here.
#设备类别
class Category(models.Model):
    name = models.CharField(_('分类名称'), max_length=50, unique=True)
    remark = models.CharField(_('备注说明'), max_length=100, blank=True, null=True)
    tm = models.DateTimeField(_('生成时间'), auto_now_add=True)

    class Meta:
        verbose_name = _('设备类别')
        verbose_name_plural = _('设备类别')

    def __str__(self):
        return self.name
    
#设备平台
class PlatForm(models.Model):
    name = models.CharField(_('平台名称'), max_length=50, unique=True)
    remark = models.CharField(_('备注说明'), max_length=100, blank=True, null=True)
    tm = models.DateTimeField(_('生成时间'), auto_now_add=True)

    class Meta:
        verbose_name = _('设备平台')
        verbose_name_plural = _('设备平台')

    def __str__(self):
        return self.name
    
#设备
class Device(models.Model):
    category = models.ForeignKey(Category, verbose_name=_('设备类别'), on_delete=models.CASCADE)
    platform = models.ForeignKey(PlatForm, verbose_name=_('设备类别'), on_delete=models.CASCADE)
    company=models.ForeignKey('company.Company',verbose_name=_('公司名称'),on_delete=models.CASCADE)
    ancestor=models.ForeignKey('company.Company',verbose_name=_('公司族系'),on_delete=models.CASCADE, related_name='device_ancestor_id')
    user=models.ForeignKey('company.User',verbose_name=_('操作人'),on_delete=models.CASCADE)
    name = models.CharField(_('设备名称'), max_length=50, db_index=True)
    status=models.SmallIntegerField(_('设备状态'),default=1,choices=((1,'正常'),(2,'休眠'),(3,'关闭')),blank=True,null=True)
    is_active = models.BooleanField(_('是否已激活'), default=True)
    is_delete = models.BooleanField(_('是否已删除'), default=False)
    is_open_live_video = models.BooleanField(_('是否开通标准流预览'), default=False)
    hik_store_id = models.CharField(_('海康云眸平台内部门店id'), max_length=100, null=True, blank=True)
    remark = models.CharField(_('备注说明'), max_length=100, null=True, blank=True)
    ridership=models.IntegerField(_('客流量冗余字段'),blank=True,null=True)
    sn = models.CharField(_('设备序列号'), max_length=50, null=True, blank=True)
    tm = models.DateTimeField(_('时间'), auto_now_add=True)

    class Meta:
        verbose_name = _('设备列表')
        verbose_name_plural = _('设备列表')

# class DeviceAnalysis(models.Model):
#     company=models.ForeignKey('company.Company',verbose_name=_('公司名称'),on_delete=models.CASCADE)
#     ancestor=models.ForeignKey('company.Company',verbose_name=_('公司族系'),on_delete=models.CASCADE, related_name='device_analysis_ancestor_id')
#     ridership_year=models.IntegerField(_('年客流量冗余字段'),blank=True,null=True)
#     ridership_today=models.IntegerField(_('今日客流量冗余字段'),blank=True,null=True)
#     tm = models.DateTimeField(_('时间'), auto_now_add=True)
#     update_tm = models.DateTimeField(_('更新时间'), auto_now_add=True)

#     class Meta:
#         verbose_name = _('设备列表')
#         verbose_name_plural = _('设备列表')