from django.db import models
from django.conf import settings

class Projekts(models.Model):
    STATUS_CHOICES = [
        ('JAUNS', 'Jauns'),
        ('DARBA', 'Darbā'),
        ('PABEIGTS', 'Pabeigts'),
        ('APTURETS', 'Apturēts'),
    ]

    # Sasaiste ar Tavu lietotāju (Klientu vai Darbinieku)
    klients = models.ForeignKey(
        settings.AUTH_USER_MODEL, 
        on_delete=models.CASCADE,
        related_name='projekti',
        null=True, blank=True
    )

    nosaukums = models.CharField(max_length=200)
    apraksts = models.TextField(blank=True)
    adrese = models.CharField(max_length=255, blank=True)
    
    statuss = models.CharField(
        max_length=20, 
        choices=STATUS_CHOICES, 
        default='JAUNS'
    )
    
    izveidots = models.DateTimeField(auto_now_add=True)
    atjaunots = models.DateTimeField(auto_now=True)

    def __str__(self):
        return f"{self.nosaukums} ({self.statuss})"

    class Meta:
        verbose_name = "Projekts"
        verbose_name_plural = "Projekti"

class Uzdevums(models.Model):
    STATUS_CHOICES = [
        ('IDEJA', '💡 Ideja'),
        ('GAIDA', 'Gaida'),
        ('PROCESA', 'Procesā'),
        ('PABEIGTS', 'Pabeigts'),
    ]

    klients = models.ForeignKey(
        settings.AUTH_USER_MODEL, 
        on_delete=models.CASCADE,
        related_name='uzdevumi'
    )
    
    tituls = models.CharField(max_length=255)
    apraksts = models.TextField(blank=True)
    
    statuss = models.CharField(
        max_length=20, 
        choices=STATUS_CHOICES, 
        default='GAIDA'
    )
    
    feedback_prasits = models.BooleanField(default=False)
    
    izveidots = models.DateTimeField(auto_now_add=True)
    atjaunots = models.DateTimeField(auto_now=True)

    def __str__(self):
        return f"{self.tituls} ({self.statuss})"

    class Meta:
        verbose_name = "Uzdevums"
        verbose_name_plural = "Uzdevumi"

class AgentaZina(models.Model):
    TIPS_CHOICES = [
        ('text', 'Teksts'),
        ('photo', 'Attēls'),
        ('audio', 'Audio'),
        ('document', 'Dokuments'),
    ]
    
    klients = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='agenta_zinas')
    tips = models.CharField(max_length=20, choices=TIPS_CHOICES, default='text')
    saturs = models.TextField(blank=True) # Tekstam
    fails = models.FileField(upload_to='tg_mediji/', blank=True, null=True) # Attēliem un Audio
    izveidots = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.klients.email} - {self.tips} ({self.izveidots})"
        
    class Meta:
        verbose_name = "Aģenta Ziņa"
        verbose_name_plural = "Aģenta Ziņas"