import uuid
from django.db import models
from django.conf import settings

class Withdraw(models.Model):
    STATUS_CHOICES = [
        ('pending', 'Pending'),
        ('approved', 'Approved'),
        ('rejected', 'Rejected'),
    ]
    
    METHOD_CHOICES = [
        ('bkash', 'bKash'),
        ('nagad', 'Nagad'),
        ('binance', 'Binance')
    ]
    
    ACCOUNT_TYPE_CHOICES = [
        ('personal', 'Personal')
    ]

    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='withdraws')
    
    amount = models.DecimalField(max_digits=10, decimal_places=2) # Original requested amount
    fee = models.DecimalField(max_digits=10, decimal_places=2, default=0.00) # 10% Charge
    final_amount = models.DecimalField(max_digits=10, decimal_places=2, default=0.00) # Amount to send
    
    method = models.CharField(max_length=15, choices=METHOD_CHOICES, default='bkash')
    phone_number = models.CharField(max_length=20, blank=True, null=True)
    pay_id = models.CharField(max_length=50, blank=True, null=True) # Specifically for Binance
    account_type = models.CharField(max_length=15, choices=ACCOUNT_TYPE_CHOICES, default='personal')
    
    status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='pending')
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.user.email} - {self.amount} ({self.get_method_display()})"