import uuid
from django.db import models
from django.utils.translation import gettext_lazy as _

class TranscriptionTask(models.Model):
    class Status(models.TextChoices):
        PENDING = 'PENDING', _('等待中')
        PROCESSING = 'PROCESSING', _('处理中')
        SUCCEEDED = 'SUCCEEDED', _('成功')
        FAILED = 'FAILED', _('失败')

    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    file_url = models.URLField(verbose_name=_('文件链接'), max_length=1024)
    task_id = models.CharField(verbose_name=_('听悟任务ID'), max_length=100, blank=True, null=True)
    status = models.CharField(
        verbose_name=_('状态'),
        max_length=20,
        choices=Status.choices,
        default=Status.PENDING
    )
    transcription = models.TextField(verbose_name=_('逐字稿'), blank=True, null=True)
    summary = models.TextField(verbose_name=_('AI总结'), blank=True, null=True)
    score = models.IntegerField(verbose_name=_('AI评分'), blank=True, null=True, help_text=_('基于转写内容的评分'))
    evaluation = models.TextField(verbose_name=_('AI评语'), blank=True, null=True)
    error_message = models.TextField(verbose_name=_('错误信息'), blank=True, null=True)
    created_at = models.DateTimeField(verbose_name=_('创建时间'), auto_now_add=True)
    updated_at = models.DateTimeField(verbose_name=_('更新时间'), auto_now=True)

    class Meta:
        verbose_name = _('转写任务')
        verbose_name_plural = _('转写任务')
        ordering = ['-created_at']

    def __str__(self):
        return f"{self.id} - {self.get_status_display()}"
