"""
系统模块模型
"""
from django.db import models
from apps.users.models import User


class Feedback(models.Model):
    """用户反馈"""

    user = models.ForeignKey(
        User, on_delete=models.CASCADE,
        related_name='feedbacks', verbose_name='用户'
    )
    content = models.TextField('反馈内容')
    contact = models.CharField('联系方式', max_length=100, blank=True, default='')
    created_at = models.DateTimeField('创建时间', auto_now_add=True)
    updated_at = models.DateTimeField('更新时间', auto_now=True)

    class Meta:
        db_table = 'feedback'
        verbose_name = '用户反馈'
        verbose_name_plural = verbose_name
        ordering = ['-created_at']

    def __str__(self):
        return f"{self.user.phone} - {self.content[:20]}"


class AppVersion(models.Model):
    """App版本"""

    PLATFORM_CHOICES = [
        ('ios', 'iOS'),
        ('android', 'Android'),
    ]

    platform = models.CharField(
        '平台', max_length=20,
        choices=PLATFORM_CHOICES
    )
    version = models.CharField('版本号', max_length=20)
    force_update = models.BooleanField('是否强制更新', default=False)
    update_url = models.URLField('下载地址', max_length=500, blank=True, default='')
    release_notes = models.TextField('更新说明', blank=True, default='')
    created_at = models.DateTimeField('创建时间', auto_now_add=True)
    updated_at = models.DateTimeField('更新时间', auto_now=True)

    class Meta:
        db_table = 'app_version'
        verbose_name = 'App版本'
        verbose_name_plural = verbose_name
        ordering = ['-created_at']

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