"""
电子吧唧 - 数据模型
"""
from django.db import models
from apps.users.models import User


class BadgeImage(models.Model):
    """吧唧图片记录"""

    SOURCE_CHOICES = [
        ('t2i', '文生图'),
        ('i2i', '图生图'),
        ('upload', '用户上传'),
    ]

    STATUS_CHOICES = [
        ('pending', '待生成'),
        ('generating', '生成中'),
        ('completed', '已完成'),
        ('failed', '失败'),
    ]

    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='badge_images')
    prompt = models.TextField(blank=True, default='')
    style = models.CharField(max_length=32, blank=True, default='')
    source = models.CharField(max_length=10, choices=SOURCE_CHOICES, default='t2i')
    image_url = models.URLField(max_length=500, blank=True, default='')
    reference_image_url = models.URLField(max_length=500, blank=True, default='')
    strength = models.FloatField(default=0.7)
    generation_status = models.CharField(
        max_length=20, choices=STATUS_CHOICES, default='pending'
    )
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'badge_image'
        ordering = ['-created_at']

    def __str__(self):
        return f'BadgeImage#{self.id} [{self.source}] {self.prompt[:30]}'
