from django.db import models
from django.contrib.auth import get_user_model

User = get_user_model()

class Transaction(models.Model):
    
    STATUS_CHOICES = [
        ('PENDING', 'Pending'),
        ('COMPLETED', 'Completed'),
        ('FAILED', 'Failed'),
    ]
    
    user = models.ForeignKey(
        User, 
        on_delete=models.CASCADE, 
        related_name='transactions'
    )
    txid = models.CharField(
        max_length=200, 
        unique=True, 
        db_index=True,
        help_text="Binance Transaction ID"
    )
    amount = models.DecimalField(
        max_digits=10, 
        decimal_places=4,
        help_text="USDT amount"
    )
    status = models.CharField(
        max_length=20, 
        choices=STATUS_CHOICES,
        default='PENDING'
    )
    created_at = models.DateTimeField(auto_now_add=True)
    
    class Meta:
        ordering = ['-created_at'] 
        db_table = 'payment_transactions'
    
    def __str__(self):
        return f"{self.user.email} - {self.amount} USDT - {self.status}"