"""PolicyDocument (Session 23).

Standards: NIST INCITS 359-2012; NIST SP 800-53 AC-3, AC-5, AC-6;
ISO 27001 A.5.15, A.5.18; ISO 15489-1 s9; Rule 9, 13, 17, 28.
"""
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("academy", "0014_teacher_student_assignment"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="PolicyDocument",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("scope", models.CharField(choices=[("ACADEMY", "Entire academy"), ("CLASS", "A specific class/grade"), ("SUBJECT", "A specific subject"), ("STUDENT", "A specific student")], db_index=True, max_length=8)),
                ("scope_value", models.CharField(blank=True, db_index=True, default="", max_length=32)),
                ("title", models.CharField(max_length=200)),
                ("body", models.TextField()),
                ("template_key", models.CharField(blank=True, default="", max_length=40)),
                ("authored_at", models.DateTimeField(auto_now_add=True)),
                ("effective_from", models.DateField()),
                ("effective_to", models.DateField(blank=True, null=True)),
                ("active", models.BooleanField(db_index=True, default=True)),
                ("version", models.PositiveIntegerField(default=1)),
                ("audience_visible", models.JSONField(blank=True, default=list, help_text='List of audiences: "students", "parents", "teachers"')),
                ("author", models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name="policies_authored", to=settings.AUTH_USER_MODEL)),
                ("supersedes", models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="superseded_by", to="academy.policydocument")),
            ],
            options={
                "verbose_name": "Policy Document",
                "verbose_name_plural": "Policy Documents",
                "ordering": ["-authored_at"],
            },
        ),
        migrations.AddIndex(
            model_name="policydocument",
            index=models.Index(fields=["scope", "scope_value", "active"], name="academy_pol_scope_va_9a5e5b_idx"),
        ),
    ]
