from django.db import models
from rest_framework_api_key.models import AbstractAPIKey
from tournaments.models import CustomUser


class APIKey(AbstractAPIKey):
    """
    API Key model linked to a specific user.
    This allows filtering API access based on the user associated with the API key.
    """
    user = models.ForeignKey(
        CustomUser,
        on_delete=models.CASCADE,
        related_name='api_keys',
        help_text='The user this API key belongs to'
    )
    
    class Meta(AbstractAPIKey.Meta):
        verbose_name = "API Key"
        verbose_name_plural = "API Keys"
    
    def __str__(self):
        return f"API Key for {self.user.username}"