from django.db import models
from django.conf import settings
from homelog.system_user import get_deleted_user


class Scanner(models.Model):
    named_id = models.CharField(max_length=40, unique=True)
    description = models.CharField(max_length=200)
    lwt_topic = models.CharField(max_length=200)
    last_online_ts = models.DateTimeField('last datetime this scanner has been online')
    assigned_channel_name = models.CharField(max_length=200)
    assigned_group_name = models.CharField(max_length=200)
    created_ts = models.DateTimeField('datetime created', auto_now_add=True)
    created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_deleted_user),
                                   related_name='created_scanners')
    changed_ts = models.DateTimeField('datetime updated', auto_now=True)
    changed_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_deleted_user),
                                   related_name='changed_scanners')

    def __str__(self):
        return self.named_id + ': ' + self.description + ' (' + str(self.last_online_ts) + ')'
