from django.db import models
from django.utils import timezone

class Project(models.Model):
    STATUS_CHOICES = [
        ('draft', 'Draft'),
        ('scripting', 'Scripting'),
        ('processing', 'Processing'),
        ('completed', 'Completed'),
    ]
    
    title = models.CharField(max_length=255)
    description = models.TextField(blank=True)
    created_at = models.DateTimeField(default=timezone.now)
    updated_at = models.DateTimeField(auto_now=True)
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='draft')
    
    def __str__(self):
        return self.title

class Script(models.Model):
    project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name='scripts')
    prompt = models.TextField()
    content = models.TextField()  # JSON or structured text from AI
    created_at = models.DateTimeField(default=timezone.now)
    
    def __str__(self):
        return f"Script for {self.project.title} ({self.created_at.strftime('%Y-%m-%d')})"

class MediaAsset(models.Model):
    ASSET_TYPE_CHOICES = [
        ('video', 'Video'),
        ('audio', 'Audio'),
        ('image', 'Image'),
    ]
    
    project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name='assets')
    file = models.FileField(upload_to='assets/%Y/%m/%d/')
    asset_type = models.CharField(max_length=10, choices=ASSET_TYPE_CHOICES)
    original_name = models.CharField(max_length=255)
    created_at = models.DateTimeField(default=timezone.now)
    
    def __str__(self):
        return self.original_name