# banking/models/payment_verification.py
from django.conf import settings
from django.db import models
from django.utils import timezone


class PaymentVerification(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

    payer_account = models.ForeignKey(
        "banking.Account",
        on_delete=models.CASCADE,
        related_name="payment_verifications_as_payer",
    )
    beneficiary_account = models.ForeignKey(
        "banking.Account",
        on_delete=models.CASCADE,
        related_name="payment_verifications_as_beneficiary",
    )


    amount = models.FloatField()

    information = models.TextField(blank=True, default="")
    variable_symbol = models.CharField(max_length=10, blank=True, default="")
    specific_symbol = models.CharField(max_length=10, blank=True, default="")
    constant_symbol = models.CharField(max_length=10, blank=True, default="")

    code = models.CharField(max_length=6)

    created_at = models.DateTimeField(auto_now_add=True)
    is_used = models.BooleanField(default=False)

    def is_expired(self) -> bool:
        # napr. 10 min platnosť
        return timezone.now() > (self.created_at + timezone.timedelta(minutes=10))

    def __str__(self):
        return f"PaymentVerification(user={self.user_id}, amount={self.amount}, used={self.is_used})"
