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


class Migration(migrations.Migration):
    """Additive: incident history table."""

    dependencies = [
        ('ftlink', '0002_uptimesample'),
        ('tenants', '0017_modulelog_acquisition'),
    ]

    operations = [
        migrations.CreateModel(
            name='Incident',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('started_at', models.DateTimeField(db_index=True)),
                ('ended_at', models.DateTimeField(blank=True, null=True)),
                ('cause', models.CharField(choices=[
                    ('dns', 'DNS not resolving'),
                    ('connect', 'Server refused the connection'),
                    ('timeout', 'Server did not respond in time'),
                    ('tls', 'TLS handshake failed'),
                    ('tls_expired', 'TLS certificate expired'),
                    ('http_5xx', 'Application error'),
                    ('http_4xx', 'Blocked or not found'),
                    ('redirect', 'Redirect loop'),
                    ('unknown', 'Unclassified'),
                ], default='unknown', max_length=20)),
                ('status_code', models.PositiveSmallIntegerField(blank=True, null=True)),
                ('error', models.CharField(blank=True, max_length=250)),
                ('diagnosis', models.TextField(blank=True, help_text='What the probes found at the time')),
                ('suggested_fix', models.CharField(blank=True, max_length=250)),
                ('fail_count', models.PositiveIntegerField(default=1)),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
                                             related_name='incidents', to='tenants.tenant')),
            ],
            options={
                'verbose_name': 'Incident',
                'verbose_name_plural': 'Incidents',
                'ordering': ['-started_at'],
            },
        ),
        migrations.AddIndex(
            model_name='incident',
            index=models.Index(fields=['tenant', 'started_at'], name='ftlink_inci_tenant__a7c9d1_idx'),
        ),
    ]
