# =============================================================
# ai_chat/models.py — AI Čata Uzdevumu Modelis
# =============================================================
import uuid
from django.db import models
from django.conf import settings


class AIChatTask(models.Model):
    """
    Katrs Gemini pieprasījums = viens task.
    Pārlūks polling-o statusu kamēr nav "done".
    """
    STATUS_PENDING = "pending"
    STATUS_DONE    = "done"
    STATUS_ERROR   = "error"
    STATUS_CHOICES = [
        (STATUS_PENDING, "Gaida"),
        (STATUS_DONE,    "Pabeigts"),
        (STATUS_ERROR,   "Kļūda"),
    ]

    id         = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    user       = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    message    = models.TextField()
    reply      = models.TextField(blank=True, default="")
    status     = models.CharField(max_length=10, choices=STATUS_CHOICES, default=STATUS_PENDING)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ["-created_at"]

    def __str__(self):
        return f"AIChatTask({self.id}, {self.status}, {self.user})"
