from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator
from uuid import uuid4


class Bonus(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
    rank_name = models.CharField(max_length=100)
    agent = models.PositiveIntegerField()
    commission_percentage = models.DecimalField(
        max_digits=5, 
        decimal_places=2,
        validators=[MinValueValidator(0), MaxValueValidator(100)]
    )
    amount = models.PositiveIntegerField(blank=True, null=True)
    royalty_bonus = models.PositiveIntegerField(blank=True, null=True)
    insentive = models.TextField(blank=True, null=True)
    is_active = models.BooleanField(default=True)
    def __str__(self):
        return f"{self.rank_name} - {self.agent} agents - {self.commission_percentage}%"

    class Meta:
        verbose_name = "Bonus"
        verbose_name_plural = "Bonuses"
        ordering = ['agent']