from django.db import models
import uuid

class KYCRequest(models.Model):
    STATUS_CHOICES = [
        ('pending', 'Ожидает проверки'),
        ('in_review', 'На рассмотрении'),
        ('approved', 'Одобрено'),
        ('rejected', 'Отклонено'),
        ('expired', 'Истекло'),
    ]
    
    uuid = models.CharField(max_length=100, unique=True, default=uuid.uuid4)
    user_id = models.CharField(max_length=255)
    team_uuid = models.CharField(max_length=100)
    team_name = models.CharField(max_length=200, blank=True)
    country_code = models.CharField(max_length=2, blank=True)
    status = models.CharField(max_length=50, choices=STATUS_CHOICES, default='pending')
    score = models.IntegerField(default=0)
    
    # Общие контактные данные
    contact_person = models.CharField(max_length=255, blank=True, default='')
    contact_email = models.EmailField(blank=True, default='')
    contact_phone = models.CharField(max_length=50, blank=True, default='')
    
    # Общий регистрационный номер (ОГРН для РФ)
    registration_number = models.CharField(max_length=50, blank=True)
    
    approved_by = models.CharField(max_length=255, null=True, blank=True)
    approved_at = models.DateTimeField(null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    
    class Meta:
        db_table = 'kyc_requests'
        
    def __str__(self):
        return f"KYC {self.user_id} - {self.status}"

class KYCRequestRussia(KYCRequest):
    # Данные компании от DaData
    company_name = models.CharField(max_length=255)
    company_full_name = models.TextField()
    inn = models.CharField(max_length=12)
    kpp = models.CharField(max_length=9, blank=True)
    ogrn = models.CharField(max_length=15, blank=True)
    address = models.TextField()
    
    # Банковские реквизиты
    bank_name = models.CharField(max_length=255)
    bik = models.CharField(max_length=9)
    correspondent_account = models.CharField(max_length=20, blank=True)
    
    class Meta:
        db_table = 'kyc_requests_russia'
        
    def save(self, *args, **kwargs):
        self.country_code = 'RU'
        super().save(*args, **kwargs)
        
    def __str__(self):
        return f"KYC RU {self.company_name} - {self.status}"