# Generated by Django 5.2 on 2025-04-25 06:07

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="DeviceType",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        max_length=100, unique=True, verbose_name="类型名称"
                    ),
                ),
                (
                    "code",
                    models.CharField(
                        max_length=10, unique=True, verbose_name="类型代码"
                    ),
                ),
                (
                    "description",
                    models.TextField(blank=True, null=True, 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": ["name"],
            },
        ),
        migrations.CreateModel(
            name="DeviceBatch",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "batch_number",
                    models.CharField(max_length=20, unique=True, verbose_name="批次号"),
                ),
                ("production_date", models.DateField(verbose_name="生产日期")),
                ("quantity", models.PositiveIntegerField(verbose_name="数量")),
                (
                    "description",
                    models.TextField(blank=True, null=True, verbose_name="批次描述"),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="创建时间"),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="更新时间"),
                ),
                (
                    "device_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="batches",
                        to="device_interaction.devicetype",
                        verbose_name="设备类型",
                    ),
                ),
            ],
            options={
                "verbose_name": "设备批次",
                "verbose_name_plural": "设备批次",
                "ordering": ["-production_date"],
            },
        ),
        migrations.CreateModel(
            name="Device",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "serial_number",
                    models.CharField(max_length=50, verbose_name="序列号"),
                ),
                (
                    "device_code",
                    models.CharField(
                        max_length=100, unique=True, verbose_name="设备码"
                    ),
                ),
                (
                    "mac_address",
                    models.CharField(
                        max_length=17, unique=True, verbose_name="MAC地址"
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(default=False, verbose_name="是否激活"),
                ),
                (
                    "activated_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="激活时间"
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="创建时间"),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="更新时间"),
                ),
                (
                    "batch",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="devices",
                        to="device_interaction.devicebatch",
                        verbose_name="设备批次",
                    ),
                ),
                (
                    "device_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="devices",
                        to="device_interaction.devicetype",
                        verbose_name="设备类型",
                    ),
                ),
            ],
            options={
                "verbose_name": "设备",
                "verbose_name_plural": "设备",
                "ordering": ["-created_at"],
                "unique_together": {("device_type", "batch", "serial_number")},
            },
        ),
        migrations.CreateModel(
            name="UserDevice",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "nickname",
                    models.CharField(
                        blank=True, max_length=100, null=True, verbose_name="设备昵称"
                    ),
                ),
                (
                    "bound_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="绑定时间"),
                ),
                (
                    "is_primary",
                    models.BooleanField(default=False, verbose_name="是否主要设备"),
                ),
                (
                    "device",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="users",
                        to="device_interaction.device",
                        verbose_name="设备",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="devices",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="用户",
                    ),
                ),
            ],
            options={
                "verbose_name": "用户设备",
                "verbose_name_plural": "用户设备",
                "ordering": ["-bound_at"],
                "unique_together": {("user", "device")},
            },
        ),
    ]
