from django.db import models
import uuid

class ExtractionTask(models.Model):
    TASK_TYPES = [
        ('fans', '粉丝 (Fans)'),
        ('following', '关注 (Following)'),
        ('comments', '评论 (Comments)'),
    ]
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    task_type = models.CharField(max_length=20, choices=TASK_TYPES, default='fans')
    raw_text = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.get_task_type_display()} - {self.created_at.strftime('%Y-%m-%d %H:%M')}"

class ExtractedUser(models.Model):
    task = models.ForeignKey(ExtractionTask, related_name='users', on_delete=models.CASCADE)
    nickname = models.CharField(max_length=255, blank=True, null=True)
    xhs_id = models.CharField(max_length=100, blank=True, null=True)
    profile_url = models.URLField(max_length=500, blank=True, null=True)
    comment_text = models.TextField(blank=True, null=True)
    extracted_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.nickname or self.xhs_id or "Unknown User"
