from django.db import models
from django.db.models.deletion import CASCADE
from django.db.models.fields.related import ForeignKey

class Hostname(models.Model):
    customuser = ForeignKey('auth_miroca.CustomUser', null=True, blank=True, on_delete=CASCADE, related_name='+', verbose_name='Пользователь')
    name = models.CharField(max_length=255, null=True, blank=True)
    area = models.CharField(max_length=255, null=True, blank=True, verbose_name='Зона температуры')

    class Meta:
        ordering = ['name']
        verbose_name = 'Зона температуры'
        verbose_name_plural = 'Зона температуры'

    def __str__(self):
        return self.name

class Month(models.Model):
    name = models.CharField(max_length=200, db_index=True,verbose_name='Месяц')
    temp = models.JSONField(default=list, null=True, blank=True, verbose_name='Список температур')


    class Meta:
        ordering = ['name']
        verbose_name = 'Месяц года'
        verbose_name_plural = 'Месяц года'

    def __str__(self):
        return self.name

class Device(models.Model):
    customuser = ForeignKey('auth_miroca.CustomUser', null=True, blank=True, on_delete=CASCADE, related_name='+', verbose_name='Пользователь')
    device_id=models.CharField(max_length=200,db_index=True,verbose_name='Id устройства')
    name =models.TextField(max_length=300,null=True,verbose_name='Имя')
    device_ip=models.CharField(max_length=200,db_index=True,null=True,verbose_name='IP адрес')
    local_key=models.TextField(max_length=200,db_index=True,null=True,verbose_name='Ключ устройства')
    device_version=models.FloatField(blank=True,null=True,verbose_name='Версия устройства')
    on_off = models.BooleanField(null=True, verbose_name='Вкл')


    class Meta:
        ordering = ['device_id']
        verbose_name = 'Устройство'
        verbose_name_plural = 'Устройства'

    def __str__(self):
        return self.device_id
