from django.db import models
from django.contrib.auth.models import User

class Submission(models.Model):
    TYPE_CHOICES = [
        ('article', 'Written Article'),
        ('video', 'Video / Documentary'),
        ('tip', 'News Tip'),
        ('photo', 'Historical Photo'),
    ]
    STATUS_CHOICES = [
        ('pending', 'Pending Review'),
        ('accepted', 'Accepted'),
        ('rejected', 'Rejected'),
        ('published', 'Published'),
    ]

    # Submitter info
    full_name       = models.CharField(max_length=200)
    email           = models.EmailField()
    bio             = models.TextField(blank=True, help_text="Brief background about yourself")
    is_researcher   = models.BooleanField(default=False, verbose_name="I am a researcher / academic")

    # Submission content
    submission_type = models.CharField(max_length=20, choices=TYPE_CHOICES)
    title           = models.CharField(max_length=300)
    description     = models.TextField(help_text="Brief description of your submission")
    content         = models.TextField(blank=True, help_text="Paste your article text here (or attach file)")
    file_upload     = models.FileField(upload_to='submissions/', blank=True,
                                       help_text="Upload .doc, .docx, .pdf, .mp4, .txt (max 50MB)")
    external_link   = models.URLField(blank=True, help_text="YouTube/Drive/Vimeo link for videos")
    category        = models.ForeignKey('articles.Category', on_delete=models.SET_NULL,
                                        null=True, blank=True)
    historical_period = models.CharField(max_length=100, blank=True)
    agree_to_terms  = models.BooleanField(default=False)

    # Admin tracking
    status          = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending')
    admin_notes     = models.TextField(blank=True)
    reviewed_by     = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
    reviewed_at     = models.DateTimeField(null=True, blank=True)
    submitted_at    = models.DateTimeField(auto_now_add=True)

    # Email notifications
    acknowledgement_sent = models.BooleanField(default=False)
    decision_sent        = models.BooleanField(default=False)

    class Meta:
        ordering = ['-submitted_at']
        verbose_name = "Submission"

    def __str__(self):
        return f"{self.title} by {self.full_name}"
