# Generated by Django 5.2 on 2025-06-01 08:53

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


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("auth", "0012_alter_user_first_name_max_length"),
        ("core", "0046_permissionrights"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="ApiClient",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=64, verbose_name="name")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "client_permissions",
                    models.ManyToManyField(
                        blank=True,
                        help_text="Specific permissions for this api client.",
                        related_name="clients",
                        to="auth.permission",
                        verbose_name="client permissions",
                    ),
                ),
                (
                    "groups",
                    models.ManyToManyField(
                        blank=True,
                        related_name="api_clients",
                        to="core.group",
                        verbose_name="groups",
                    ),
                ),
                (
                    "owner",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="api_clients",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="owner",
                    ),
                ),
            ],
            options={
                "verbose_name": "api client",
                "verbose_name_plural": "api clients",
            },
        ),
        migrations.CreateModel(
            name="ApiKey",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(blank=True, default="", verbose_name="name")),
                (
                    "prefix",
                    models.CharField(
                        editable=False, max_length=5, verbose_name="prefix"
                    ),
                ),
                (
                    "hashed_key",
                    models.CharField(
                        db_index=True,
                        editable=False,
                        max_length=136,
                        verbose_name="hashed key",
                    ),
                ),
                ("revoked", models.BooleanField(default=False, verbose_name="revoked")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "client",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="api_keys",
                        to="api.apiclient",
                        verbose_name="api client",
                    ),
                ),
            ],
            options={
                "verbose_name": "api key",
                "verbose_name_plural": "api keys",
                "permissions": [("revoke_apikey", "Revoke API keys")],
            },
        ),
    ]
