# Generated by Django 6.0.1 on 2026-01-29 14:38

from django.conf import settings
from django.db import migrations, models
from django.utils import timezone

from saas.utils.token import gen_token_key


class Migration(migrations.Migration):
    initial = True

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

    operations = [
        migrations.CreateModel(
            name='UserToken',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=48)),
                ('key', models.CharField(default=gen_token_key, editable=False, max_length=48, unique=True)),
                ('scope', models.TextField(blank=True, null=True)),
                ('last_used_at', models.DateTimeField(blank=True, null=True)),
                ('expires_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(default=timezone.now, editable=False)),
                (
                    'tenant',
                    models.ForeignKey(
                        blank=True, null=True, on_delete=models.CASCADE, related_name='+', to=settings.SAAS_TENANT_MODEL
                    ),
                ),
                ('user', models.ForeignKey(on_delete=models.CASCADE, related_name='+', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'saas_user_token',
                'ordering': ('-created_at',),
            },
        ),
    ]
