from django.db import models
from django_resized import ResizedImageField
import uuid

class BaseModel(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    id = models.UUIDField(
        default=uuid.uuid4, unique=True, primary_key=True, editable=False
    )

    class Meta:
        abstract = True

    
class Gallery(BaseModel):
    title         = models.CharField(max_length=200, blank=True, null=True)
    main_image    = ResizedImageField(quality=90, upload_to="store/")
    slug          = models.SlugField(null=True, blank=True, unique=True)
    active        = models.BooleanField(default=False, blank=True, null=True)
    
    class Meta:
        verbose_name_plural = "shops"
        ordering = ["-updated_at"]

    def __str__(self):
        return self.title
   

class OthergalleryImages(BaseModel):
    shop = models.ForeignKey(
        Gallery,
        on_delete=models.CASCADE,
        null=True,
        blank=True,
    )
    
    other_shop_images = ResizedImageField(quality=90, upload_to="shop/", blank=True, null=True)

    class Meta:
        verbose_name_plural = "Other shop images"

    def __str__(self):
        return self.shop.title