from django.db import models
from common.models.base import TimeStampedModel
from producers_products.models.producers_products import ProducersProducts

class PromotedFor(models.IntegerChoices):
    COVER_PAGE_SLIDER = 1
    PRODUCT_PROMOTE_SLIDER = 2
    NEW_ARRIVAL = 3

class PromotedProducts(TimeStampedModel):
    promoted_for = models.IntegerField(choices=PromotedFor)
    promoted_product = models.ForeignKey(ProducersProducts,on_delete=models.CASCADE,related_name="promoted_product")
    title = models.CharField(max_length=255)
    icon = models.ImageField(upload_to="promoted_products")
    image = models.ImageField(upload_to="promoted_products")
    description = models.TextField()
    offer_start_date = models.DateField()
    offer_end_date = models.DateField()

    class Meta:
        ordering = ['id']
        verbose_name_plural = 'Producers_promoted_products'

    def __str__(self):
        return self.title
    
    def soft_delete(self):
        if self.is_active:
            self.is_active = False
            self.save(update_fields=['is_active'])