# Generated by Django 5.2.10 on 2026-01-22 03:05

import apps.sigils.fields
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("repos", "0004_githubevent"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="GitHubApp",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("is_seed_data", models.BooleanField(default=False, editable=False)),
                ("is_user_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
                ("name", models.CharField(blank=True, max_length=255)),
                ("webhook_url", models.URLField(blank=True)),
                (
                    "webhook_secret",
                    apps.sigils.fields.SigilShortAutoField(blank=True, max_length=255),
                ),
                ("webhook_events", models.JSONField(blank=True, default=list)),
                ("webhook_active", models.BooleanField(default=True)),
                (
                    "webhook_content_type",
                    models.CharField(
                        choices=[("json", "JSON"), ("form", "Form")],
                        default="json",
                        max_length=20,
                    ),
                ),
                ("webhook_insecure_ssl", models.BooleanField(default=False)),
                ("display_name", models.CharField(max_length=255)),
                ("app_id", models.PositiveBigIntegerField(unique=True)),
                ("app_slug", models.SlugField(blank=True, max_length=255)),
                ("app_url", models.URLField(blank=True)),
                ("homepage_url", models.URLField(blank=True)),
                ("callback_url", models.URLField(blank=True)),
                ("setup_url", models.URLField(blank=True)),
                ("redirect_url", models.URLField(blank=True)),
                (
                    "client_id",
                    apps.sigils.fields.SigilShortAutoField(blank=True, max_length=255),
                ),
                (
                    "client_secret",
                    apps.sigils.fields.SigilShortAutoField(blank=True, max_length=255),
                ),
                ("private_key", apps.sigils.fields.SigilLongAutoField(blank=True)),
                ("public_key", apps.sigils.fields.SigilLongAutoField(blank=True)),
                ("permissions", models.JSONField(blank=True, default=dict)),
                ("default_events", models.JSONField(blank=True, default=list)),
                (
                    "auth_method",
                    models.CharField(
                        choices=[
                            ("app", "GitHub App"),
                            ("user_token", "User Token"),
                            ("user_password", "User Password"),
                            ("temp_password", "Temporary Password"),
                        ],
                        default="app",
                        max_length=20,
                    ),
                ),
                (
                    "auth_token",
                    apps.sigils.fields.SigilShortAutoField(
                        blank=True,
                        help_text="Personal access token or OAuth token for the auth user.",
                        max_length=255,
                    ),
                ),
                (
                    "auth_password",
                    apps.sigils.fields.SigilShortAutoField(
                        blank=True,
                        help_text="Password for the auth user. Temporary passwords are permitted for the system account when configured.",
                        max_length=255,
                    ),
                ),
                (
                    "auth_user",
                    models.ForeignKey(
                        blank=True,
                        help_text="User to authenticate as for non-admin GitHub access or delegated operations.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="github_apps",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "GitHub App",
                "verbose_name_plural": "GitHub Apps",
            },
        ),
        migrations.CreateModel(
            name="GitHubAppInstall",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("is_seed_data", models.BooleanField(default=False, editable=False)),
                ("is_user_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
                ("installation_id", models.PositiveBigIntegerField()),
                ("account_id", models.PositiveBigIntegerField(blank=True, null=True)),
                ("account_login", models.CharField(blank=True, max_length=255)),
                ("target_type", models.CharField(blank=True, max_length=50)),
                ("repository_selection", models.CharField(blank=True, max_length=50)),
                ("permissions", models.JSONField(blank=True, default=dict)),
                ("events", models.JSONField(blank=True, default=list)),
                ("installed_at", models.DateTimeField(blank=True, null=True)),
                ("suspended_at", models.DateTimeField(blank=True, null=True)),
                ("app_version", models.CharField(blank=True, max_length=50)),
                ("app_revision", models.CharField(blank=True, max_length=50)),
                (
                    "app",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="installs",
                        to="repos.githubapp",
                    ),
                ),
            ],
            options={
                "verbose_name": "GitHub App Install",
                "verbose_name_plural": "GitHub App Installs",
                "indexes": [
                    models.Index(
                        fields=["installation_id"], name="github_install_id_idx"
                    ),
                    models.Index(
                        fields=["account_login"], name="github_install_login_idx"
                    ),
                ],
                "constraints": [
                    models.UniqueConstraint(
                        fields=("app", "installation_id"),
                        name="unique_github_app_install",
                    )
                ],
            },
        ),
    ]
