from django.db import models
from django.contrib.auth.models import User

from django.utils.translation import gettext_lazy as _

from apps.sites.models import Submissions

class UserProfile(models.Model):
    
    MATURE = [
        ("H", "Hide"),
        ("B", "Blur"),
        ("S", "Show"),
        ]
    
    ITEMS_PER_PAGE = [
        (24, "24"),
        (48, "48"),
        (72, "72"),
        ]
    
    POST_SEEN_DELAY = [
        (15, "15"),
        (30, "30"),
        (60, "60"),
        (90, "90"),
        ]
    
    user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True, unique=True)
    show_mature = models.CharField(max_length=2, choices=MATURE, default=MATURE[0][0])
    items_per_page = models.IntegerField(choices=ITEMS_PER_PAGE, default=ITEMS_PER_PAGE[0][0])
    post_seen_delay = models.IntegerField(choices=POST_SEEN_DELAY, default=POST_SEEN_DELAY[1][1], help_text="Delay in seconds before marking a post as seen") 

    class Meta:
        verbose_name = _("User Profile")
        verbose_name_plural = _("User Profiles")
        
    def __str__(self):
        return self.user.username


class SeenPost(models.Model):
    user = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
    post = models.ForeignKey(Submissions, on_delete=models.CASCADE)
    timestamp = models.DateTimeField(auto_now_add=True)

    class Meta:
        verbose_name = _("Seen Post")
        verbose_name_plural = _("Seen Posts")
    
    def __str__(self) -> str:
        return self.user.user.username + " - " + self.post.submission_hash