# Generated by Django 5.2 on 2025-05-08 09:47

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="Achievement",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=100, verbose_name="成就名称")),
                ("description", models.TextField(verbose_name="成就描述")),
                (
                    "icon",
                    models.ImageField(
                        blank=True,
                        null=True,
                        upload_to="achievements/icons/",
                        verbose_name="成就图标",
                    ),
                ),
                (
                    "conditions",
                    models.JSONField(
                        help_text="JSON格式的成就获取条件", verbose_name="获取条件"
                    ),
                ),
                (
                    "rarity",
                    models.CharField(
                        choices=[
                            ("common", "普通"),
                            ("uncommon", "不普通"),
                            ("rare", "稀有"),
                            ("epic", "史诗"),
                            ("legendary", "传说"),
                        ],
                        default="common",
                        max_length=20,
                        verbose_name="稀有度",
                    ),
                ),
                (
                    "achievement_type",
                    models.CharField(
                        choices=[
                            ("login", "登录相关"),
                            ("activity", "活动相关"),
                            ("social", "社交相关"),
                            ("usage", "使用相关"),
                            ("special", "特殊成就"),
                            ("hidden", "隐藏成就"),
                        ],
                        default="special",
                        max_length=20,
                        verbose_name="成就类型",
                    ),
                ),
                (
                    "is_hidden",
                    models.BooleanField(default=False, verbose_name="隐藏成就"),
                ),
                ("points", models.IntegerField(default=0, verbose_name="成就积分")),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="创建时间"),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="更新时间"),
                ),
            ],
            options={
                "verbose_name": "成就",
                "verbose_name_plural": "成就",
                "ordering": ["rarity", "name"],
                "indexes": [
                    models.Index(fields=["name"], name="achievement_name_4cdaf8_idx"),
                    models.Index(
                        fields=["achievement_type"],
                        name="achievement_achieve_e4a5f8_idx",
                    ),
                    models.Index(
                        fields=["rarity"], name="achievement_rarity_f59009_idx"
                    ),
                ],
            },
        ),
        migrations.CreateModel(
            name="UserAchievement",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "acquired_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="获得时间"),
                ),
                (
                    "acquisition_data",
                    models.JSONField(
                        blank=True,
                        help_text="JSON格式的获得成就时的相关数据",
                        null=True,
                        verbose_name="获得数据",
                    ),
                ),
                (
                    "notification_shown",
                    models.BooleanField(default=False, verbose_name="已显示通知"),
                ),
                (
                    "achievement",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="users",
                        to="achievement_app.achievement",
                        verbose_name="成就",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="achievements",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="用户",
                    ),
                ),
            ],
            options={
                "verbose_name": "用户成就",
                "verbose_name_plural": "用户成就",
                "ordering": ["-acquired_at"],
                "indexes": [
                    models.Index(
                        fields=["user"], name="achievement_user_id_bcdb94_idx"
                    ),
                    models.Index(
                        fields=["achievement"], name="achievement_achieve_23f9a6_idx"
                    ),
                    models.Index(
                        fields=["acquired_at"], name="achievement_acquire_c78032_idx"
                    ),
                ],
                "unique_together": {("user", "achievement")},
            },
        ),
    ]
