# Generated by Django 5.1.7 on 2025-03-17 05:38

import uuid
from saas_auth.util import gen_token_key
from django.utils import timezone
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),
        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.CharField(max_length=255)),
                ('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_auth_user_token',
                'ordering': ('-created_at',),
            },
        ),
        migrations.CreateModel(
            name='Session',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('session_key', models.CharField(max_length=40)),
                ('user_agent', models.TextField()),
                ('expiry_date', models.DateTimeField()),
                ('location', models.JSONField(default=dict)),
                ('created_at', models.DateTimeField(default=timezone.now)),
                ('last_used', models.DateTimeField(default=timezone.now)),
                ('user', models.ForeignKey(on_delete=models.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'saas_auth_session',
                'unique_together': {('user', 'session_key')},
                'ordering': ('-last_used',),
            },
        ),
    ]
