from django.db import models
from shared_models.common.base import BaseModel

class CustomerUPI(BaseModel):
    id = models.AutoField(primary_key=True, editable=False)
    customer_id = models.IntegerField(db_index=True)
    upi_id = models.CharField(max_length=255)
    display_name = models.CharField(max_length=255)
    is_primary = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    comment = models.TextField(blank=True, null=True, help_text='Additional notes about this UPI ID')

    class Meta:
        app_label = 'shared_customer_upi'
        db_table = 'shared_customer_upi'
        verbose_name = 'Customer UPI'
        verbose_name_plural = 'Customer UPIs'
        ordering = ['-created_at']
        indexes = [
            models.Index(fields=['customer_id']),
            models.Index(fields=['upi_id']),
        ]
        permissions = [
            # Base CRUD permissions (auto-generated by Django)
            # view_customerupi, add_customerupi, change_customerupi, delete_customerupi
            
            # UPI-specific action permissions
            ('verify_customerupi', 'Can verify customer UPI'),
            ('approve_customerupi', 'Can approve customer UPI'),
            ('set_primary_customerupi', 'Can set primary UPI'),
        ]

    def __str__(self):
        return f"Customer UPI {self.upi_id} (Customer ID: {self.customer_id})"
