from django.db import models
from django.utils import timezone

class Log(models.Model):
    # Usamos BigAutoField para el BIGINT id de tu tabla
    id = models.BigAutoField(primary_key=True)
    user_id = models.IntegerField(default=0)
    user = models.CharField(max_length=255, default='anonimo')
    app_id = models.IntegerField(default=0)
    # GenericIPAddressField para el tipo INET de Postgres
    remote_address = models.GenericIPAddressField(null=True, blank=True)
    request = models.JSONField(null=True, blank=True)  # Para JSONB
    response = models.JSONField(null=True, blank=True) # Para JSONB
    status_code = models.CharField(max_length=10, default='0')
    path = models.CharField(max_length=255)
    method = models.CharField(max_length=10)
    createdAt = models.DateTimeField(default=timezone.now)
    updatedAt = models.DateTimeField(auto_now=True)


    class Meta:
        db_table = 'audit_logs'
        # managed = True  <-- Asegúrate de que no esté en False

    def __str__(self):
        return f"{self.method} {self.path} ({self.status_code})"