from django.db import models
from . import BaseModel, CustomUser
import uuid

class Log(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
    date = models.DateTimeField()
    user = models.ForeignKey(CustomUser, blank=True, null=True, on_delete=models.SET_NULL, related_name='logs')
    message = models.TextField(blank=True, null=True)

    def __str__(self):
        datetime = self.date.strftime("%Y-%m-%d %H:%M")
        if self.user:
            return f"{datetime} | {self.user.username} | {self.message}"
        else:
            return f"{datetime} | {self.message}"

    def discord_string(self):
        return str(self)
