from django.contrib.auth.models import User
from django.db import models
from django.urls import reverse
from django.utils import timezone
from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _


class Album(models.Model):
    title = models.CharField(verbose_name="Titel", max_length=200)
    slug = models.SlugField(unique=True, null=True, blank=True)

    folder_name = models.CharField(verbose_name="Ordner Name", max_length=200)
    thumbnail = models.CharField(
        verbose_name="Thumbnail", max_length=200, null=True, blank=True
    )

    event_date = models.DateField(
        verbose_name="Event Datum", null=True, blank=True, default=timezone.now
    )

    photographer = models.CharField(
        verbose_name="Fotograph(en)", max_length=200, null=True, blank=True
    )

    DRAFT = "10"
    PUBLIC = "20"
    STATUS = (
        (DRAFT, "DRAFT"),
        (PUBLIC, "PUBLIC"),
    )
    status = models.CharField(max_length=2, choices=STATUS, default=DRAFT)

    description = models.TextField(null=True, blank=True)

    # Managers
    objects = models.Manager()

    class Meta:
        verbose_name = _("Album")
        verbose_name_plural = _("Alben")

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("album", kwargs={"slug": self.slug})

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.title)

        super().save(*args, **kwargs)
