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

class Clipboard(models.Model):
    identifier = models.CharField(max_length=255, unique=True)
    content = models.TextField(blank=True)
    file = models.FileField(upload_to='uploads/', blank=True, null=True)
    expires_at = models.DateTimeField(null=False, blank=False)

    def __str__(self):
        return self.identifier

    def remaining_time(self):
        now = timezone.now()
        if self.expires_at > now:
            delta = self.expires_at - now
            hours, remainder = divmod(delta.seconds, 3600)
            minutes, seconds = divmod(remainder, 60)
            if hours > 0:
                return f"{hours} hours, {minutes} minutes"
            else:
                return f"{minutes} minutes"
        else:
            return "Expired"