# Generated by GitHub Copilot on 2026-01-06

# Django
from django.db import migrations


def remove_materialexchangeconfig_model_permissions(apps, schema_editor):
    """Remove Django auto-generated model permissions for MaterialExchangeConfig.

    These are (add/change/delete/view) and are not used by Indy Hub.
    """

    ContentType = apps.get_model("contenttypes", "ContentType")
    Permission = apps.get_model("auth", "Permission")

    ct = ContentType.objects.filter(
        app_label="indy_hub", model="materialexchangeconfig"
    ).first()
    if not ct:
        return

    codenames = [
        "add_materialexchangeconfig",
        "change_materialexchangeconfig",
        "delete_materialexchangeconfig",
        "view_materialexchangeconfig",
    ]

    Permission.objects.filter(content_type=ct, codename__in=codenames).delete()


class Migration(migrations.Migration):

    dependencies = [
        ("indy_hub", "0062_alter_esicontract_options_and_more"),
    ]

    operations = [
        migrations.AlterModelOptions(
            name="materialexchangeconfig",
            options={
                "default_permissions": (),
                "verbose_name": "Material Exchange Configuration",
                "verbose_name_plural": "Material Exchange Configurations",
            },
        ),
        migrations.RunPython(
            remove_materialexchangeconfig_model_permissions,
            reverse_code=migrations.RunPython.noop,
        ),
    ]
