# Generated by Django 5.1.3 on 2025-12-21 05:52

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


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("accounts", "0001_initial"),
        ("sources", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="GitHubInstallation",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "installation_id",
                    models.BigIntegerField(help_text="GitHub's installation ID", unique=True),
                ),
                (
                    "account_login",
                    models.CharField(help_text="GitHub username or org name", max_length=255),
                ),
                (
                    "account_type",
                    models.CharField(
                        choices=[("User", "User"), ("Organization", "Organization")],
                        max_length=20,
                    ),
                ),
                ("account_id", models.BigIntegerField(help_text="GitHub's account ID")),
                (
                    "account_avatar_url",
                    models.URLField(blank=True, max_length=500, null=True),
                ),
                (
                    "_access_token",
                    models.TextField(blank=True, db_column="access_token"),
                ),
                ("token_expires_at", models.DateTimeField(blank=True, null=True)),
                ("permissions", models.JSONField(blank=True, default=dict)),
                ("suspended_at", models.DateTimeField(blank=True, null=True)),
                (
                    "workspace",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="github_installation",
                        to="accounts.workspace",
                    ),
                ),
            ],
            options={
                "verbose_name": "GitHub Installation",
                "verbose_name_plural": "GitHub Installations",
            },
        ),
        migrations.CreateModel(
            name="GitHubRepository",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("repo_id", models.BigIntegerField(help_text="GitHub's repository ID")),
                (
                    "owner",
                    models.CharField(help_text="Repository owner (user/org)", max_length=255),
                ),
                ("name", models.CharField(help_text="Repository name", max_length=255)),
                (
                    "full_name",
                    models.CharField(help_text="Full name (owner/name)", max_length=512),
                ),
                ("private", models.BooleanField(default=False)),
                (
                    "sync_status",
                    models.CharField(
                        choices=[
                            ("pending", "Pending"),
                            ("syncing", "Syncing"),
                            ("active", "Active"),
                            ("error", "Error"),
                            ("paused", "Paused"),
                            ("disabled", "Disabled"),
                        ],
                        default="pending",
                        max_length=20,
                    ),
                ),
                ("last_sync_at", models.DateTimeField(blank=True, null=True)),
                ("last_sync_error", models.TextField(blank=True)),
                (
                    "sync_cursors",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Pagination cursors for incremental sync",
                    ),
                ),
                ("is_archived", models.BooleanField(default=False)),
                (
                    "installation",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="repositories",
                        to="integrations.githubinstallation",
                    ),
                ),
                (
                    "source",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="github_repository",
                        to="sources.source",
                    ),
                ),
            ],
            options={
                "verbose_name": "GitHub Repository",
                "verbose_name_plural": "GitHub Repositories",
                "indexes": [
                    models.Index(fields=["sync_status"], name="integration_sync_st_c87fdd_idx"),
                    models.Index(fields=["is_archived"], name="integration_is_arch_81e03a_idx"),
                ],
                "unique_together": {("installation", "repo_id")},
            },
        ),
    ]
