from django.db import models
from django_ckeditor_5.fields import CKEditor5Field


class RecruitAFriend(models.Model):
    title = models.CharField(max_length=255, default="Recluta a un amigo")
    information = models.CharField(max_length=255, default="Información")
    content = CKEditor5Field('Contenido', config_name='default')
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.title

class RecruitReward(models.Model):
    required_friends = models.IntegerField()
    reward_name = models.CharField(max_length=100)
    item_id = models.IntegerField()
    item_quantity = models.IntegerField(default=1)
    item_link = models.URLField()
    icon_class = models.CharField(max_length=50, help_text="Clase CSS para el icono (ej. 'icontinyl q3')")

    def __str__(self):
        return f"{self.required_friends} amigos - {self.reward_name}"

class ClaimedReward(models.Model):
    recruit_reward = models.ForeignKey(RecruitReward, on_delete=models.CASCADE, related_name='claimed_rewards')
    account_id = models.IntegerField()
    character_name = models.CharField(max_length=100)
    username = models.CharField(max_length=100)
    claimed_at = models.DateTimeField(auto_now_add=True)
    ip_address = models.CharField(max_length=45, default='127.0.0.1')  # Añadir un valor predeterminado

    def __str__(self):
        return f"{self.username} - {self.recruit_reward.reward_name} - {self.claimed_at}"
