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

from . import BaseModel, CustomUser

class Purchase(BaseModel):
    id = models.BigIntegerField(primary_key=True, unique=True, editable=True)
    user = models.ForeignKey(CustomUser, on_delete=models.CASCADE, related_name='purchases')
    purchase_date = models.DateTimeField()
    product_id = models.CharField(max_length=100)
    quantity = models.IntegerField(null=True, blank=True)
    revocation_date = models.DateTimeField(null=True, blank=True)
    expiration_date = models.DateTimeField(null=True, blank=True)

    def delete_dependencies(self):
        pass

    def __str__(self):
        return f"{self.id} > {self.product_id} - {self.purchase_date} - {self.user.username}"

    def is_active(self):
        return self.expiration_date > timezone.now()
