from django.db import models

class Application(models.Model):
    name = models.CharField(max_length=255)
    version = models.CharField(max_length=100)
    vendor = models.CharField(max_length=255)

    def __str__(self):
        return f"{self.name} {self.version}"

class Vulnerability(models.Model):
    SEVERITY_CHOICES = [
        ('Critical', 'Critical'),
        ('High', 'High'),
        ('Medium', 'Medium'),
        ('Low', 'Low'),
    ]
    STATUS_CHOICES = [
        ('New', 'New'),
        ('Acknowledged', 'Acknowledged'),
        ('In-Progress', 'In-Progress'),
        ('Resolved', 'Resolved'),
    ]

    cve_id = models.CharField(max_length=50, unique=True)
    description = models.TextField()
    severity = models.CharField(max_length=10, choices=SEVERITY_CHOICES)
    application = models.ForeignKey(Application, on_delete=models.CASCADE, related_name='vulnerabilities')
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='New')
    discovered_at = models.DateTimeField(auto_now_add=True)
    last_updated = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.cve_id
