"""
Migration to seed granular page-specific permissions and role templates
"""
from django.db import migrations
from django.core.management import call_command


def seed_permissions(apps, schema_editor):
    """Seed page permissions and role templates"""
    # Seed page permissions
    call_command('seed_page_permissions')
    # Seed role templates
    call_command('seed_role_templates')


def reverse_seed_permissions(apps, schema_editor):
    """Remove seeded permissions"""
    PagePermission = apps.get_model('users', 'PagePermission')
    RolePermissionTemplate = apps.get_model('users', 'RolePermissionTemplate')
    
    PagePermission.objects.all().delete()
    RolePermissionTemplate.objects.all().delete()


class Migration(migrations.Migration):
    dependencies = [
        ('users', '0024_enhanced_permissions_models'),
    ]

    operations = [
        migrations.RunPython(seed_permissions, reverse_seed_permissions),
    ]
