import uuid
from django.db import models
from django.utils import timezone

class QRToken(models.Model):
    user = models.ForeignKey('account.Person', on_delete = models.SET_NULL, null=True)
    token = models.UUIDField(default=uuid.uuid4, unique=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return f"{self.user} QR"

class AttendanceLog(models.Model):
    CHECK_IN = 'IN'
    CHECK_OUT = 'OUT'

    ACTION_CHOICES = [
        (CHECK_IN, 'Check In'),
        (CHECK_OUT, 'Check Out'),
    ]

    user = models.ForeignKey('account.Person', on_delete = models.SET_NULL, null=True)
    action = models.CharField(max_length=3, choices=ACTION_CHOICES)
    timestamp = models.DateTimeField(default = timezone.now)
    # time_recorded = models.DateTimeField(auto_now_add=True)
    ip_address = models.GenericIPAddressField(null=True, blank=True)

    def __str__(self):
        return f"{self.user} - {self.action} @ {self.timestamp}"
