# Generated 2026-05-04 — FRREP-AC005 (CollectionGroupAccess ACL pivot)

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


class Migration(migrations.Migration):

    dependencies = [
        ("auth", "0012_alter_user_first_name_max_length"),
        ("repository_documents", "0002_collection_upload_notification_recipients_keyword_and_more"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="CollectionGroupAccess",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "permission_level",
                    models.CharField(
                        choices=[
                            ("view", "View"),
                            ("comment", "View + comment"),
                            ("edit", "View + comment + edit metadata"),
                        ],
                        default="view",
                        max_length=12,
                    ),
                ),
                ("granted_at", models.DateTimeField(auto_now_add=True)),
                (
                    "expires_at",
                    models.DateTimeField(
                        blank=True,
                        help_text="Optional expiry. After this datetime the grant is treated as inactive.",
                        null=True,
                    ),
                ),
                (
                    "note",
                    models.CharField(
                        blank=True,
                        help_text="Internal note explaining why this group was granted access.",
                        max_length=255,
                    ),
                ),
                (
                    "collection",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="group_access",
                        to="repository_documents.collection",
                    ),
                ),
                (
                    "granted_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="repository_collection_grants_issued",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "group",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="repository_collection_grants",
                        to="auth.group",
                    ),
                ),
            ],
            options={
                "verbose_name": "Collection group access grant",
                "verbose_name_plural": "Collection group access grants",
                "ordering": ["collection__name", "group__name"],
                "unique_together": {("collection", "group")},
            },
        ),
    ]
