from django.db import models
from django.contrib.contenttypes.fields import GenericRelation
from smart.models import SmartModule, SmartPush


class Mosquito(models.Model):
    name = models.CharField(max_length=100, verbose_name='设备名称')
    device_id = models.CharField(max_length=100, verbose_name='设备ID')
    region = models.CharField(max_length=50, verbose_name='区域')
    smart_module = GenericRelation(SmartModule)

    class Meta:
        verbose_name = '灭蚊灯'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        pass

    def get_api_url(self):
        pass


class MosqPost(models.Model):
    smart_push = models.ForeignKey(SmartPush, on_delete='PROTECT')
    mosq = models.ForeignKey(Mosquito, verbose_name='灭蚊灯', on_delete='PROTECT')
    led = models.PositiveIntegerField(verbose_name='灭蚊数')
    energy = models.PositiveIntegerField(verbose_name='电量')
    # signal = models.IntegerField(verbose_name='信号')
    # coordinate = models.CharField(max_length=100, verbose_name='坐标')
    time = models.DateTimeField(auto_now=False, auto_now_add=True)

    class Meta:
        verbose_name = '灭蚊数据'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '{0}: {1}'.format(self.mosq.name, self.led)

    def get_api_url(self):
        pass
