# Generated by Django 6.0.1 on 2026-01-28 10:03

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("devices", "0001_initial"),
        ("spirits", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.AddField(
            model_name="devicebatch",
            name="created_by",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                to=settings.AUTH_USER_MODEL,
                verbose_name="创建人",
            ),
        ),
        migrations.AddField(
            model_name="device",
            name="batch",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="devices",
                to="devices.devicebatch",
                verbose_name="所属批次",
            ),
        ),
        migrations.AddField(
            model_name="devicebatch",
            name="device_type",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="batches",
                to="devices.devicetype",
                verbose_name="设备类型",
            ),
        ),
        migrations.AddField(
            model_name="device",
            name="device_type",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.PROTECT,
                related_name="devices",
                to="devices.devicetype",
                verbose_name="设备类型",
            ),
        ),
        migrations.AddField(
            model_name="userdevice",
            name="device",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="user_devices",
                to="devices.device",
                verbose_name="设备",
            ),
        ),
        migrations.AddField(
            model_name="userdevice",
            name="spirit",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="user_devices",
                to="spirits.spirit",
                verbose_name="绑定的智能体",
            ),
        ),
        migrations.AddField(
            model_name="userdevice",
            name="user",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="user_devices",
                to=settings.AUTH_USER_MODEL,
                verbose_name="用户",
            ),
        ),
        migrations.AlterUniqueTogether(
            name="devicebatch",
            unique_together={("device_type", "batch_no", "production_date")},
        ),
        migrations.AddIndex(
            model_name="device",
            index=models.Index(
                fields=["mac_address"], name="device_mac_add_09f85c_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="device",
            index=models.Index(fields=["status"], name="device_status_6321a6_idx"),
        ),
        migrations.AlterUniqueTogether(
            name="userdevice",
            unique_together={("user", "device")},
        ),
    ]
