# Generated by Django 4.2.7 on 2023-12-04 11:09

import datetime
import uuid

import django.contrib.auth.validators
import django.core.validators
import django.db.models.deletion
import django.utils.timezone
import taggit.managers
from django.conf import settings
from django.db import migrations, models

import firefighter.incidents.models.priority
import firefighter.incidents.models.severity
import firefighter.incidents.models.user


class Migration(migrations.Migration):
    replaces = [
        ("incidents", "0001_initial"),
        ("incidents", "0002_incidentupdate_component"),
        ("incidents", "0003_alter_incidentupdate_severity"),
        ("incidents", "0004_auto_20210607_1053"),
        ("incidents", "0005_alter_incidentupdate_communication_lead"),
        ("incidents", "0006_alter_user_slack_id"),
        ("incidents", "0007_alter_incident_id"),
        ("incidents", "0008_auto_20210624_1135"),
        ("incidents", "0009_auto_20210625_1721_squashed_0014_alter_severity_value"),
        ("incidents", "0010_auto_20210627_2155"),
        ("incidents", "0011_auto_20210628_1427"),
        ("incidents", "0012_auto_20210702_1634"),
        (
            "incidents",
            "0013_environment_value_squashed_0017_rename_slack_groups_component_slack_conversations",
        ),
        ("incidents", "0014_auto_20210809_1052"),
        ("incidents", "0015_auto_20210820_1534"),
        ("incidents", "0016_auto_20210825_1039"),
        ("incidents", "0017_auto_20210829_1608"),
        ("incidents", "0018_alter_incidentupdate__status"),
        ("incidents", "0019_auto_20210903_1410"),
        ("incidents", "0020_auto_20211104_0951"),
        ("incidents", "0021_auto_20211112_1038"),
        ("incidents", "0022_alter_user_name"),
        ("incidents", "0023_auto_20220622_1559"),
        ("incidents", "0024_alter_incidentmembership_inviter"),
        ("incidents", "0025_alter_incident_commander_and_more"),
        ("incidents", "0026_alter_user_options"),
        ("incidents", "0027_component_private"),
        ("incidents", "0028_incident_private_alter_component_order_and_more"),
        ("incidents", "0027_remove_component_slack_conversations"),
        ("incidents", "0029_merge_20221031_1156"),
        ("incidents", "0030_status_enum_constraints"),
        ("incidents", "0031_incidentcosttype_incidentcost"),
        ("incidents", "0032_alter_incidentcost_options_and_more"),
        ("incidents", "0033_user_bot"),
        ("incidents", "0034_component_deploy_warning"),
        ("incidents", "0035_user_avatar"),
        ("incidents", "0036_severity_enabled_create_severity_enabled_update_and_more"),
        ("incidents", "0037_priority_migration"),
        ("incidents", "0038_alter_incident_severity"),
        (
            "incidents",
            "0039_impact_impacttype_incidentimpact_impact_impact_type_and_more",
        ),
        ("incidents", "0040_priority_recommended_response_type"),
        ("incidents", "0041_impactlevel_and_more"),
        ("incidents", "0042_alter_impactlevel_id"),
        ("incidents", "0043_impactlevel_emoji_impacttype_emoji"),
        ("incidents", "0044_dynamic_metrics"),
        ("incidents", "0045_dynamic_incident_roles"),
        ("incidents", "0046_dynamic_incident_roles_bis"),
        ("incidents", "0047_incidentroletype_incidents_incidentroletype_slug_check"),
        ("incidents", "0048_remove_incidentroletype_best_practices_and_more"),
        ("incidents", "0049_incidentrole_created_at_incidentrole_updated_at"),
        ("incidents", "0050_remove_incidentrole_unique_incident_role_and_more"),
    ]

    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
        ("taggit", "0003_taggeditem_add_unique_index"),
        ("auth", "0012_alter_user_first_name_max_length"),
    ]

    operations = [
        migrations.CreateModel(
            name="Component",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("name", models.CharField(max_length=128)),
                ("slack_groups", models.CharField(default="", max_length=128)),
                ("cachet_id", models.IntegerField(null=True)),
                ("on_call", models.SmallIntegerField(default=0)),
                ("description", models.TextField()),
                ("order", models.IntegerField(default=0)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "ordering": ["order"],
            },
        ),
        migrations.CreateModel(
            name="Environment",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("name", models.CharField(max_length=128, unique=True)),
                ("description", models.CharField(max_length=128, unique=True)),
                ("order", models.IntegerField(default=0)),
                ("default", models.BooleanField(default=False)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("value", models.CharField(max_length=16, unique=True)),
            ],
        ),
        migrations.CreateModel(
            name="Group",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("name", models.CharField(max_length=128, unique=True)),
                ("description", models.TextField(blank=True)),
                ("order", models.IntegerField(default=0, unique=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name="Severity",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "name",
                    models.CharField(default="SEVXX", max_length=128, unique=True),
                ),
                ("emoji", models.CharField(default="🔥", max_length=5)),
                ("description", models.CharField(max_length=128)),
                ("order", models.IntegerField(default=0)),
                ("default", models.BooleanField(default=False)),
                ("needs_postmortem", models.BooleanField(default=False)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("value", models.IntegerField(unique=True)),
                (
                    "reminder_time",
                    models.DurationField(
                        default=datetime.timedelta(seconds=3600),
                        help_text="Time before an incident without any incident update will receive a reminder.",
                    ),
                ),
            ],
            options={
                "verbose_name_plural": "severities",
                "ordering": ["order"],
            },
        ),
        migrations.CreateModel(
            name="User",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="User fullname. Prefer to set `first_name` and `last_name`, and get `full_name`. ",
                        max_length=128,
                    ),
                ),
                ("email", models.EmailField(max_length=128, unique=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "date_joined",
                    models.DateTimeField(
                        default=django.utils.timezone.now, verbose_name="date joined"
                    ),
                ),
                (
                    "first_name",
                    models.CharField(
                        blank=True, max_length=150, verbose_name="first name"
                    ),
                ),
                (
                    "groups",
                    models.ManyToManyField(
                        blank=True,
                        help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
                        related_name="user_set",
                        related_query_name="user",
                        to="auth.group",
                        verbose_name="groups",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        default=True,
                        help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
                        verbose_name="active",
                    ),
                ),
                (
                    "is_staff",
                    models.BooleanField(
                        default=False,
                        help_text="Designates whether the user can log into this admin site.",
                        verbose_name="staff status",
                    ),
                ),
                (
                    "is_superuser",
                    models.BooleanField(
                        default=False,
                        help_text="Designates that this user has all permissions without explicitly assigning them.",
                        verbose_name="superuser status",
                    ),
                ),
                (
                    "last_login",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="last login"
                    ),
                ),
                (
                    "last_name",
                    models.CharField(
                        blank=True, max_length=150, verbose_name="last name"
                    ),
                ),
                (
                    "password",
                    models.CharField(
                        default="!0PRxvh7bM2Twf93xctRExwjMqbaOnK2VaVkKiUzu",
                        max_length=128,
                        verbose_name="password",
                    ),
                ),
                (
                    "user_permissions",
                    models.ManyToManyField(
                        blank=True,
                        help_text="Specific permissions for this user.",
                        related_name="user_set",
                        related_query_name="user",
                        to="auth.permission",
                        verbose_name="user permissions",
                    ),
                ),
                (
                    "username",
                    models.CharField(
                        error_messages={
                            "unique": "A user with that username already exists."
                        },
                        help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
                        max_length=150,
                        unique=True,
                        validators=[
                            django.contrib.auth.validators.UnicodeUsernameValidator()
                        ],
                        verbose_name="username",
                    ),
                ),
            ],
            options={
                "ordering": ["username"],
            },
            managers=[
                ("objects", firefighter.incidents.models.user.UserManager()),
            ],
        ),
        migrations.CreateModel(
            name="Incident",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False
                    ),
                ),
                ("title", models.CharField(max_length=128)),
                ("description", models.TextField()),
                (
                    "_status",
                    models.IntegerField(
                        choices=[
                            (10, "Open"),
                            (20, "Investigating"),
                            (30, "Mitigating"),
                            (40, "Mitigated"),
                            (50, "Post-mortem"),
                            (60, "Closed"),
                        ],
                        db_column="status",
                        default=10,
                        verbose_name="Status",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("closed_at", models.DateTimeField(blank=True, null=True)),
                (
                    "commander",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="incidents_commander",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "communication_lead",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="incidents_communication_lead",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "component",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="incidents.component",
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "environment",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="incidents.environment",
                    ),
                ),
                (
                    "severity",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="incidents.severity",
                    ),
                ),
                (
                    "time_to_detect",
                    models.DurationField(
                        blank=True, db_column="time_to_detect", null=True
                    ),
                ),
                (
                    "time_to_internal_response",
                    models.DurationField(
                        blank=True, db_column="time_to_internal_response", null=True
                    ),
                ),
                (
                    "time_to_resolve",
                    models.DurationField(
                        blank=True, db_column="time_to_resolve", null=True
                    ),
                ),
                (
                    "time_to_repair",
                    models.DurationField(
                        blank=True, db_column="time_to_repair", null=True
                    ),
                ),
                (
                    "ignore",
                    models.BooleanField(
                        default=False,
                        help_text="An ignored incident can be closed right away. In the future, it won't affect statistics or appear in reports. This is useful for duplicates incidents, or false-positives.",
                    ),
                ),
                (
                    "time_to_fix",
                    models.DurationField(
                        blank=True, db_column="time_to_fix", null=True
                    ),
                ),
                (
                    "time_to_recovery",
                    models.DurationField(
                        blank=True, db_column="time_to_recovery", null=True
                    ),
                ),
                (
                    "time_to_respond",
                    models.DurationField(
                        blank=True, db_column="time_to_respond", null=True
                    ),
                ),
                (
                    "tags",
                    taggit.managers.TaggableManager(
                        blank=True,
                        help_text="A comma-separated list of tags.",
                        through="taggit.TaggedItem",
                        to="taggit.Tag",
                        verbose_name="Tags",
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="component",
            name="group",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT, to="incidents.group"
            ),
        ),
        migrations.AlterField(
            model_name="component",
            name="description",
            field=models.TextField(blank=True),
        ),
        migrations.RemoveField(
            model_name="component",
            name="cachet_id",
        ),
        migrations.RenameField(
            model_name="component",
            old_name="slack_groups",
            new_name="slack_conversations",
        ),
        migrations.RemoveField(
            model_name="component",
            name="on_call",
        ),
        migrations.RemoveField(
            model_name="component",
            name="slack_conversations",
        ),
        migrations.CreateModel(
            name="IncidentUpdate",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("message", models.TextField(blank=True, null=True)),
                (
                    "_status",
                    models.IntegerField(
                        blank=True,
                        choices=[
                            (10, "Open"),
                            (20, "Investigating"),
                            (30, "Mitigating"),
                            (40, "Mitigated"),
                            (50, "Post-mortem"),
                            (60, "Closed"),
                        ],
                        db_column="status",
                        null=True,
                        verbose_name="Status",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "commander",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="commander_for",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "communication_lead",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="communication_lead_for",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "incident",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="incidents.incident",
                    ),
                ),
                (
                    "severity",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=models.SET(
                            firefighter.incidents.models.severity.Severity.get_default
                        ),
                        to="incidents.severity",
                    ),
                ),
                (
                    "component",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="incidents.component",
                    ),
                ),
                ("description", models.TextField(blank=True, null=True)),
                ("title", models.CharField(blank=True, max_length=128, null=True)),
                ("event_ts", models.DateTimeField()),
                ("event_type", models.CharField(blank=True, max_length=64, null=True)),
            ],
            options={
                "ordering": ["-event_ts"],
            },
        ),
        migrations.AlterField(
            model_name="incident",
            name="component",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT, to="incidents.component"
            ),
        ),
        migrations.AlterField(
            model_name="incident",
            name="created_by",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="incidents_created_by",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AlterField(
            model_name="incident",
            name="environment",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT, to="incidents.environment"
            ),
        ),
        migrations.AlterField(
            model_name="incident",
            name="severity",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT, to="incidents.severity"
            ),
        ),
        migrations.CreateModel(
            name="IncidentMembership",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "incident",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="incidents.incident",
                    ),
                ),
                (
                    "inviter",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="members",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="incident",
            name="members",
            field=models.ManyToManyField(
                through="incidents.IncidentMembership", to=settings.AUTH_USER_MODEL
            ),
        ),
        migrations.AlterField(
            model_name="incident",
            name="commander",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="incidents_commander",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AlterField(
            model_name="incident",
            name="communication_lead",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="incidents_communication_lead",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AlterField(
            model_name="incident",
            name="created_by",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="incidents_created_by",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="incident",
            name="private",
            field=models.BooleanField(
                default=False,
                help_text="A private incident is not communicated in #tech-incidents, and its created conversation is private. In the future, we may restrict the visibility to incident members only.",
            ),
        ),
        migrations.AlterField(
            model_name="component",
            name="order",
            field=models.IntegerField(
                default=0,
                help_text="Order of the component in the list. Should be unique per `Group`.",
            ),
        ),
        migrations.AddField(
            model_name="component",
            name="private",
            field=models.BooleanField(
                default=False,
                help_text="If true, incident created with this component won't be communicated, and conversations will be made private. This is useful for sensitive components. In the future, private incidents may be visible only to its members.",
            ),
        ),
        migrations.AddConstraint(
            model_name="incident",
            constraint=models.CheckConstraint(
                check=models.Q(("_status__in", [10, 20, 30, 40, 50, 60])),
                name="incidents_incident__status_valid",
            ),
        ),
        migrations.AddConstraint(
            model_name="incidentupdate",
            constraint=models.CheckConstraint(
                check=models.Q(("_status__in", [10, 20, 30, 40, 50, 60])),
                name="incidents_incidentupdate__status_valid",
            ),
        ),
        migrations.CreateModel(
            name="IncidentCostType",
            fields=[
                ("id", models.BigAutoField(primary_key=True, serialize=False)),
                ("name", models.CharField(max_length=255, unique=True)),
                ("description", models.TextField(blank=True, null=True)),
                ("category", models.CharField(blank=True, max_length=255, null=True)),
                ("default", models.BooleanField(default=False)),
                ("editable", models.BooleanField(default=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "Incident cost type",
                "verbose_name_plural": "Incident cost types",
            },
        ),
        migrations.CreateModel(
            name="IncidentCost",
            fields=[
                ("id", models.BigAutoField(primary_key=True, serialize=False)),
                (
                    "amount",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        help_text="Amount in EUR",
                        max_digits=10,
                        null=True,
                    ),
                ),
                ("details", models.TextField(blank=True, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "cost_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="incident_cost_set",
                        to="incidents.incidentcosttype",
                    ),
                ),
                (
                    "incident",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="incident_cost_set",
                        to="incidents.incident",
                    ),
                ),
            ],
            options={
                "verbose_name": "Incident cost",
                "verbose_name_plural": "Incident costs",
            },
        ),
        migrations.AddField(
            model_name="user",
            name="bot",
            field=models.BooleanField(
                default=False,
                help_text="Used for non-person accounts (e.g. integrations that have bot/shared accounts.",
            ),
        ),
        migrations.AddField(
            model_name="component",
            name="deploy_warning",
            field=models.BooleanField(
                default=True,
                help_text="If true, a warning will be sent when creating an incident of high severity with this component.",
            ),
        ),
        migrations.AddField(
            model_name="user",
            name="avatar",
            field=models.URLField(
                blank=True,
                help_text="URL to user avatar. Can be hosted externally.",
                max_length=1024,
                null=True,
            ),
        ),
        migrations.AddField(
            model_name="severity",
            name="enabled_create",
            field=models.BooleanField(
                default=True,
                help_text="Can you create a new incident with this severity?",
            ),
        ),
        migrations.AddField(
            model_name="severity",
            name="enabled_update",
            field=models.BooleanField(
                default=True, help_text="Can you update an incident to this severity?"
            ),
        ),
        migrations.AlterField(
            model_name="severity",
            name="order",
            field=models.IntegerField(default=0, unique=True),
        ),
        migrations.AddConstraint(
            model_name="severity",
            constraint=models.UniqueConstraint(
                condition=models.Q(("default", True)),
                fields=("default",),
                name="unique__default",
            ),
        ),
        migrations.CreateModel(
            name="Priority",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("name", models.CharField(max_length=128, unique=True)),
                ("value", models.IntegerField(unique=True)),
                ("emoji", models.CharField(default="🔥", max_length=5)),
                ("description", models.CharField(max_length=128)),
                ("order", models.IntegerField(default=0, unique=True)),
                ("default", models.BooleanField(default=False)),
                ("needs_postmortem", models.BooleanField(default=False)),
                (
                    "enabled_create",
                    models.BooleanField(
                        default=True,
                        help_text="Can you create a new incident with this priority?",
                    ),
                ),
                (
                    "enabled_update",
                    models.BooleanField(
                        default=True,
                        help_text="Can you update an incident to this priority?",
                    ),
                ),
                (
                    "reminder_time",
                    models.DurationField(
                        default=datetime.timedelta(seconds=3600),
                        help_text="Time before an incident without any incident update will receive a reminder.",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name_plural": "priorities",
                "ordering": ["order"],
            },
        ),
        migrations.AddConstraint(
            model_name="priority",
            constraint=models.UniqueConstraint(
                condition=models.Q(("default", True)),
                fields=("default",),
                name="unique_priority_default",
            ),
        ),
        migrations.AlterModelOptions(
            name="severity",
            options={
                "ordering": ["order"],
                "verbose_name": "severity (legacy)",
                "verbose_name_plural": "severities (legacy)",
            },
        ),
        migrations.AddField(
            model_name="priority",
            name="sla",
            field=models.DurationField(
                default=datetime.timedelta(seconds=3600),
                help_text="Service Level Agreement",
                verbose_name="SLA",
            ),
        ),
        migrations.AlterField(
            model_name="incident",
            name="severity",
            field=models.ForeignKey(
                help_text="Severity (legacy, superseded by priority)",
                on_delete=django.db.models.deletion.PROTECT,
                to="incidents.severity",
            ),
        ),
        migrations.AddField(
            model_name="incidentupdate",
            name="priority",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=models.SET(
                    firefighter.incidents.models.priority.Priority.get_default
                ),
                to="incidents.priority",
            ),
        ),
        migrations.AlterField(
            model_name="incidentupdate",
            name="severity",
            field=models.ForeignKey(
                blank=True,
                help_text="Superseded by priority",
                null=True,
                on_delete=models.SET(
                    firefighter.incidents.models.severity.Severity.get_default
                ),
                to="incidents.severity",
            ),
        ),
        migrations.AddField(
            model_name="incident",
            name="priority",
            field=models.ForeignKey(
                help_text="Priority",
                on_delete=django.db.models.deletion.PROTECT,
                to="incidents.priority",
            ),
        ),
        migrations.AlterField(
            model_name="incident",
            name="severity",
            field=models.ForeignKey(
                blank=True,
                help_text="Severity (legacy, superseded by priority)",
                null=True,
                on_delete=django.db.models.deletion.PROTECT,
                to="incidents.severity",
            ),
        ),
        migrations.CreateModel(
            name="Impact",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "value",
                    models.CharField(
                        choices=[
                            ("NA", "❔ N/A"),
                            ("HI", "🔼 High"),
                            ("MD", "➡️ Medium"),
                            ("LO", "🔽 Low"),
                            ("NO", "0️⃣ None"),
                        ],
                        max_length=2,
                    ),
                ),
                ("details", models.TextField(blank=True, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name="ImpactType",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=64)),
                ("help_text", models.CharField(max_length=128)),
                ("value", models.SlugField(unique=True)),
            ],
            options={
                "verbose_name_plural": "Impact Types",
            },
        ),
        migrations.CreateModel(
            name="IncidentImpact",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "impact",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="incidents.impact",
                    ),
                ),
                (
                    "incident",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="incidents.incident",
                    ),
                ),
            ],
            options={
                "verbose_name": "Incident impact",
                "verbose_name_plural": "Incident impacts",
            },
        ),
        migrations.AddField(
            model_name="impact",
            name="impact_type",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE, to="incidents.impacttype"
            ),
        ),
        migrations.AddField(
            model_name="incident",
            name="impacts",
            field=models.ManyToManyField(
                through="incidents.IncidentImpact", to="incidents.impact"
            ),
        ),
        migrations.AddConstraint(
            model_name="impact",
            constraint=models.CheckConstraint(
                check=models.Q(("value__in", ["NA", "HI", "MD", "LO", "NO"])),
                name="incidents_impact_value_valid",
            ),
        ),
        migrations.AddField(
            model_name="priority",
            name="recommended_response_type",
            field=models.CharField(blank=True, max_length=128, null=True),
        ),
        migrations.CreateModel(
            name="ImpactLevel",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Description for the impact level for this impact type.",
                        max_length=75,
                        null=True,
                    ),
                ),
                (
                    "value",
                    models.CharField(
                        choices=[
                            ("HI", "🔼 High"),
                            ("MD", "➡️ Medium"),
                            ("LO", "🔽 Low"),
                            ("NO", "0️⃣ N/A"),
                        ],
                        default="NO",
                        max_length=2,
                    ),
                ),
                ("order", models.PositiveSmallIntegerField(default=10)),
            ],
        ),
        migrations.RemoveConstraint(
            model_name="impact",
            name="incidents_impact_value_valid",
        ),
        migrations.RemoveField(
            model_name="impact",
            name="value",
        ),
        migrations.AddField(
            model_name="impacttype",
            name="order",
            field=models.PositiveSmallIntegerField(default=10),
        ),
        migrations.AddField(
            model_name="impactlevel",
            name="impact_type",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="levels",
                to="incidents.impacttype",
            ),
        ),
        migrations.AddField(
            model_name="impact",
            name="impact_level",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT, to="incidents.impactlevel"
            ),
            preserve_default=False,
        ),
        migrations.AddConstraint(
            model_name="impactlevel",
            constraint=models.UniqueConstraint(
                fields=("impact_type", "value"), name="unique_impact_level"
            ),
        ),
        migrations.AddConstraint(
            model_name="impactlevel",
            constraint=models.CheckConstraint(
                check=models.Q(("value__in", ["HI", "MD", "LO", "NO"])),
                name="incidents_impactlevel_value_valid",
            ),
        ),
        migrations.AlterField(
            model_name="impactlevel",
            name="id",
            field=models.UUIDField(editable=False, primary_key=True, serialize=False),
        ),
        migrations.AddField(
            model_name="impactlevel",
            name="emoji",
            field=models.CharField(default="ℹ️", max_length=5),  # noqa: RUF001
        ),
        migrations.AddField(
            model_name="impacttype",
            name="emoji",
            field=models.CharField(default="ℹ️", max_length=5),  # noqa: RUF001
        ),
        migrations.CreateModel(
            name="MilestoneType",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Title or name (e.g. Recovered)", max_length=50
                    ),
                ),
                (
                    "event_type",
                    models.SlugField(
                        help_text="Technical name, slugified version of the name (e.g. recovered)",
                        unique=True,
                    ),
                ),
                (
                    "summary",
                    models.CharField(
                        help_text="Slack Markdown summary of the milestone (e.g. *Recovered*, when the impact is no longer apparent.)",
                        max_length=250,
                    ),
                ),
                (
                    "user_editable",
                    models.BooleanField(
                        help_text="Can be edited by users (else, system event)."
                    ),
                ),
                (
                    "required",
                    models.BooleanField(
                        help_text="Is required for the incident to be considered as complete."
                    ),
                ),
                (
                    "asked_for",
                    models.BooleanField(
                        default=True, help_text="Asked for in the form."
                    ),
                ),
                ("description", models.TextField(blank=True, null=True)),
            ],
            options={
                "verbose_name": "Milestone Type",
                "verbose_name_plural": "Milestone Types",
            },
        ),
        migrations.CreateModel(
            name="MetricType",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Title or name (e.g. Time to Detect)", max_length=50
                    ),
                ),
                (
                    "code",
                    models.CharField(
                        help_text="Short code (e.g. TTD)", max_length=10, unique=True
                    ),
                ),
                ("description", models.TextField()),
                (
                    "type",
                    models.SlugField(
                        blank=True,
                        help_text="Technical name, slugified version of the title (e.g. time_to_detect)",
                        unique=True,
                    ),
                ),
                (
                    "milestone_lhs",
                    models.ForeignKey(
                        help_text="The milestone that ends the metric (duration = milestone_lhs - milestone_rhs)",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="metric_type_lhs",
                        to="incidents.milestonetype",
                    ),
                ),
                (
                    "milestone_rhs",
                    models.ForeignKey(
                        help_text="The milestone that starts the metric (duration = milestone_lhs - milestone_rhs)",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="metric_type_rhs",
                        to="incidents.milestonetype",
                    ),
                ),
            ],
            options={
                "verbose_name": "Metric Type",
                "verbose_name_plural": "Metric Types",
            },
        ),
        migrations.CreateModel(
            name="IncidentMetric",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "duration",
                    models.DurationField(
                        validators=[
                            django.core.validators.MinValueValidator(
                                datetime.timedelta(0)
                            )
                        ]
                    ),
                ),
                (
                    "incident",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="metric_set",
                        to="incidents.incident",
                    ),
                ),
                (
                    "metric_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="incidents.metrictype",
                    ),
                ),
            ],
            options={
                "verbose_name": "Incident Metric",
                "verbose_name_plural": "Incident Metrics",
            },
        ),
        migrations.AddConstraint(
            model_name="incidentmetric",
            constraint=models.UniqueConstraint(
                fields=("incident", "metric_type"),
                name="incidents_incidentmetric__incident_metric_type_unique",
            ),
        ),
        migrations.RemoveField(
            model_name="incident",
            name="time_to_detect",
        ),
        migrations.RemoveField(
            model_name="incident",
            name="time_to_fix",
        ),
        migrations.RemoveField(
            model_name="incident",
            name="time_to_internal_response",
        ),
        migrations.RemoveField(
            model_name="incident",
            name="time_to_recovery",
        ),
        migrations.RemoveField(
            model_name="incident",
            name="time_to_repair",
        ),
        migrations.RemoveField(
            model_name="incident",
            name="time_to_resolve",
        ),
        migrations.RemoveField(
            model_name="incident",
            name="time_to_respond",
        ),
        migrations.AddField(
            model_name="incident",
            name="metrics",
            field=models.ManyToManyField(
                through="incidents.IncidentMetric", to="incidents.metrictype"
            ),
        ),
        migrations.AddConstraint(
            model_name="incidentmetric",
            constraint=models.CheckConstraint(
                check=models.Q(("duration__gte", datetime.timedelta(0))),
                name="incidents_incidentmetric__duration_positive",
            ),
        ),
        migrations.AddConstraint(
            model_name="metrictype",
            constraint=models.CheckConstraint(
                check=models.Q(
                    ("milestone_lhs", models.F("milestone_rhs")), _negated=True
                ),
                name="incidents_metrictype__milestone_lhs_not_equal_milestone_rhs",
                violation_error_message="The milestone that ends the metric cannot be the same as the milestone that starts the metric.",
            ),
        ),
        migrations.AlterField(
            model_name="incident",
            name="commander",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="incidents_commander",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AlterField(
            model_name="incident",
            name="communication_lead",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="incidents_communication_lead",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.CreateModel(
            name="IncidentRoleType",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=255)),
                ("slug", models.SlugField(max_length=255, unique=True)),
                (
                    "emoji",
                    models.CharField(
                        blank=True,
                        help_text="The emoji to represent this role.",
                        max_length=5,
                    ),
                ),
                ("summary", models.TextField()),
                ("description", models.TextField()),
                ("aka", models.TextField(blank=True)),
                ("responsibilities", models.TextField(blank=True)),
                ("requirements", models.TextField(blank=True)),
                ("best_practices", models.TextField(blank=True)),
                (
                    "required",
                    models.BooleanField(
                        default=False,
                        help_text="If the role is required, it will be automatically attributed to the incident creator.",
                    ),
                ),
                (
                    "order",
                    models.PositiveSmallIntegerField(
                        default=0, help_text="The display order of the role."
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="IncidentRole",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
            ],
        ),
        migrations.RemoveField(
            model_name="incidentmembership",
            name="inviter",
        ),
        migrations.AddConstraint(
            model_name="incidentmembership",
            constraint=models.UniqueConstraint(
                fields=("incident", "user"), name="unique_incident_membership"
            ),
        ),
        migrations.AddField(
            model_name="incidentrole",
            name="incident",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="roles",
                to="incidents.incident",
            ),
        ),
        migrations.AddField(
            model_name="incidentrole",
            name="user",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="roles",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="incidentrole",
            name="role",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="roles",
                to="incidents.incidentroletype",
            ),
        ),
        migrations.AddConstraint(
            model_name="incidentrole",
            constraint=models.UniqueConstraint(
                fields=("incident", "user", "role"), name="unique_incident_role"
            ),
        ),
        migrations.AddField(
            model_name="incident",
            name="roles",
            field=models.ManyToManyField(
                related_name="incident_roles_set",
                through="incidents.IncidentRole",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AlterField(
            model_name="incidentrole",
            name="incident",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="roles_set",
                to="incidents.incident",
            ),
        ),
        migrations.AlterField(
            model_name="incidentrole",
            name="role",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="roles_set",
                to="incidents.incidentroletype",
            ),
        ),
        migrations.AlterField(
            model_name="incidentrole",
            name="user",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="roles_set",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AlterField(
            model_name="impactlevel",
            name="value",
            field=models.CharField(
                choices=[
                    ("HI", "High"),
                    ("MD", "Medium"),
                    ("LO", "Low"),
                    ("NO", "N/A"),
                ],
                default="NO",
                max_length=2,
            ),
        ),
        migrations.RemoveField(
            model_name="incident",
            name="commander",
        ),
        migrations.RemoveField(
            model_name="incident",
            name="communication_lead",
        ),
        migrations.AddConstraint(
            model_name="incidentroletype",
            constraint=models.CheckConstraint(
                check=models.Q(("slug__regex", "^[a-z0-9\\_]+$")),
                name="incidents_incidentroletype_slug_check",
            ),
        ),
        migrations.RemoveField(
            model_name="incidentroletype",
            name="best_practices",
        ),
        migrations.RemoveField(
            model_name="incidentroletype",
            name="requirements",
        ),
        migrations.RemoveField(
            model_name="incidentroletype",
            name="responsibilities",
        ),
        migrations.AddField(
            model_name="incidentroletype",
            name="summary_first_person",
            field=models.TextField(
                blank=True,
                help_text="First person version of the summary, used for instance in Slack messages to assignees.",
                null=True,
            ),
        ),
        migrations.AddField(
            model_name="incidentrole",
            name="created_at",
            field=models.DateTimeField(
                auto_now_add=True, default=django.utils.timezone.now
            ),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name="incidentrole",
            name="updated_at",
            field=models.DateTimeField(auto_now=True),
        ),
        migrations.RemoveConstraint(
            model_name="incidentrole",
            name="unique_incident_role",
        ),
        migrations.RenameField(
            model_name="incidentrole",
            old_name="role",
            new_name="role_type",
        ),
        migrations.AddConstraint(
            model_name="incidentrole",
            constraint=models.UniqueConstraint(
                fields=("incident", "user", "role_type"), name="unique_incident_role"
            ),
        ),
    ]
