# Generated by Django 5.2.9 on 2025-12-13 17:32

import apps.totp.models
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="TOTPDevice",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="The human-readable name of this device.",
                        max_length=64,
                    ),
                ),
                (
                    "throttling_failure_timestamp",
                    models.DateTimeField(
                        blank=True,
                        default=None,
                        help_text="A timestamp of the last failed verification attempt. Null if last attempt succeeded.",
                        null=True,
                    ),
                ),
                (
                    "throttling_failure_count",
                    models.PositiveIntegerField(
                        default=0, help_text="Number of successive failed attempts."
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="The date and time when this device was initially created in the system.",
                        null=True,
                    ),
                ),
                (
                    "last_used_at",
                    models.DateTimeField(
                        blank=True,
                        help_text="The most recent date and time this device was used.",
                        null=True,
                    ),
                ),
                (
                    "key",
                    models.CharField(
                        default=apps.totp.models.default_key,
                        help_text="A hex-encoded secret key of up to 40 bytes.",
                        max_length=80,
                        validators=[apps.totp.models.key_validator],
                    ),
                ),
                (
                    "step",
                    models.PositiveSmallIntegerField(
                        default=30, help_text="The time step in seconds."
                    ),
                ),
                (
                    "t0",
                    models.BigIntegerField(
                        default=0,
                        help_text="The Unix time at which to begin counting steps.",
                    ),
                ),
                (
                    "digits",
                    models.PositiveSmallIntegerField(
                        choices=[(6, 6), (8, 8)],
                        default=6,
                        help_text="The number of digits to expect in a token.",
                    ),
                ),
                (
                    "tolerance",
                    models.PositiveSmallIntegerField(
                        default=1,
                        help_text="The number of time steps in the past or future to allow.",
                    ),
                ),
                (
                    "drift",
                    models.SmallIntegerField(
                        default=0,
                        help_text="The number of time steps the prover is known to deviate from our clock.",
                    ),
                ),
                (
                    "last_t",
                    models.BigIntegerField(
                        default=-1,
                        help_text="The t value of the latest verified token. The next token must be at a higher time step.",
                    ),
                ),
                (
                    "confirmed",
                    models.BooleanField(
                        default=False, help_text="Is this device ready for use?"
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        help_text="The user that this device belongs to.",
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "TOTP device",
                "verbose_name_plural": "TOTP devices",
                "ordering": ("user", "name"),
                "abstract": False,
                "constraints": [
                    models.UniqueConstraint(
                        fields=("user", "name"), name="totp_device_unique_name_per_user"
                    )
                ],
            },
        ),
    ]
