from django.db import models
from photobook.models import PhotoBook
from events.models import Booking

class PaymentType(models.Model):
    name = models.CharField(max_length=255, unique=True)

    def __str__(self):
        return f"{self.name}"

class Payment(models.Model):
    PAYMENT_STATUS_CHOICES = [
        ('I', 'Initiated'),
        ('P', 'Partial'),
        ('C', 'Completed'),
        ('F', 'Failed'),
    ]
    uid = models.CharField(max_length=255, unique=True, db_index=True)
    status = models.CharField(
        max_length=1,
        choices=PAYMENT_STATUS_CHOICES,
        blank=True
    )
    type = models.ForeignKey(PaymentType, on_delete=models.CASCADE, null=True)

    booking = models.ForeignKey(Booking, on_delete=models.CASCADE, null=True)
    photobook = models.ForeignKey(PhotoBook, on_delete=models.CASCADE, null=True)
    
    information = models.JSONField(null=True, blank=True)
    termsAndCondition = models.JSONField(null=True, blank=True)
    createdAt = models.DateTimeField(auto_now_add=True)
    updatedAt = models.DateTimeField(auto_now=True)

    def __str__(self):
        return f"{self.uid} - {self.type} - "