from django.db import models


class Vote(models.Model):
    """Track votes/thumbs up for blog posts, tools, and other content"""
    CONTENT_TYPES = [
        ('blog', 'Blog Post'),
        ('tool', 'Tool/Application'),
        ('species_alert', 'Species Alert Report'),
    ]
    
    content_type = models.CharField(max_length=20, choices=CONTENT_TYPES)
    content_id = models.CharField(max_length=255)  # slug or tool identifier
    vote_count = models.IntegerField(default=0)
    
    # Track sessions that have voted to prevent duplicate votes
    voted_sessions = models.JSONField(default=list)
    
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    
    class Meta:
        unique_together = ['content_type', 'content_id']
        indexes = [
            models.Index(fields=['content_type', 'content_id']),
        ]
    
    def __str__(self):
        return f"{self.content_type}:{self.content_id} - {self.vote_count} votes"
