# Generated by Django 3.2.5 on 2022-05-31 14:46

import apps.user_management.models.organization
import apps.user_management.models.team
import apps.user_management.models.user
import datetime
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import mirage.fields
import django_migration_linter as linter


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('alerts', '0001_squashed_initial'),
        ('slack', '0001_squashed_initial'),
    ]

    operations = [
        linter.IgnoreMigration(),
        migrations.CreateModel(
            name='Organization',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('maintenance_duration', models.DurationField(choices=[(datetime.timedelta(seconds=3600), '1 hour'), (datetime.timedelta(seconds=10800), '3 hours'), (datetime.timedelta(seconds=21600), '6 hours'), (datetime.timedelta(seconds=43200), '12 hours'), (datetime.timedelta(days=1), '24 hours')], default=None, null=True)),
                ('maintenance_mode', models.IntegerField(choices=[(0, 'Debug'), (1, 'Maintenance')], default=None, null=True)),
                ('maintenance_uuid', models.CharField(default=None, max_length=250, null=True, unique=True)),
                ('maintenance_started_at', models.DateTimeField(default=None, null=True)),
                ('public_primary_key', models.CharField(default=apps.user_management.models.organization.generate_public_primary_key_for_organization, max_length=20, unique=True, validators=[django.core.validators.MinLengthValidator(13)])),
                ('stack_id', models.PositiveIntegerField()),
                ('org_id', models.PositiveIntegerField()),
                ('stack_slug', models.CharField(max_length=300)),
                ('org_slug', models.CharField(max_length=300)),
                ('org_title', models.CharField(max_length=300)),
                ('grafana_url', models.URLField()),
                ('api_token', mirage.fields.EncryptedCharField(max_length=300)),
                ('api_token_status', models.IntegerField(choices=[(0, 'API Token Status Pending'), (1, 'API Token Status Ok'), (2, 'API Token Status Failed')], default=0)),
                ('gcom_token', mirage.fields.EncryptedCharField(default=None, max_length=300, null=True)),
                ('gcom_token_org_last_time_synced', models.DateTimeField(default=None, null=True)),
                ('last_time_synced', models.DateTimeField(default=None, null=True)),
                ('is_resolution_note_required', models.BooleanField(default=False)),
                ('archive_alerts_from', models.DateField(default='1970-01-01')),
                ('general_log_channel_id', models.CharField(default=None, max_length=100, null=True)),
                ('acknowledge_remind_timeout', models.IntegerField(choices=[(0, 'Never remind about ack-ed incidents'), (1, 'Remind every 1 hour'), (2, 'Remind every 3 hours'), (3, 'Remind every 5 hours'), (4, 'Remind every 10 hours')], default=0)),
                ('unacknowledge_timeout', models.IntegerField(choices=[(0, 'and never unack'), (1, 'and unack in 5 min if no response'), (2, 'and unack in 15 min if no response'), (3, 'and unack in 30 min if no response'), (4, 'and unack in 45 min if no response')], default=0)),
                ('datetime', models.DateTimeField(auto_now_add=True)),
                ('pricing_version', models.PositiveIntegerField(choices=[(0, 'Free public beta')], default=0)),
                ('is_amixr_migration_started', models.BooleanField(default=False)),
            ],
        ),
        migrations.CreateModel(
            name='Team',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('public_primary_key', models.CharField(default=apps.user_management.models.team.generate_public_primary_key_for_team, max_length=20, unique=True, validators=[django.core.validators.MinLengthValidator(13)])),
                ('team_id', models.PositiveIntegerField()),
                ('name', models.CharField(max_length=300)),
                ('email', models.CharField(blank=True, default=None, max_length=300, null=True)),
                ('avatar_url', models.URLField()),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='teams', to='user_management.organization')),
            ],
        ),
        migrations.CreateModel(
            name='User',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('public_primary_key', models.CharField(default=apps.user_management.models.user.generate_public_primary_key_for_user, max_length=20, unique=True, validators=[django.core.validators.MinLengthValidator(13)])),
                ('user_id', models.PositiveIntegerField()),
                ('email', models.EmailField(max_length=254)),
                ('name', models.CharField(max_length=300)),
                ('username', models.CharField(max_length=300)),
                ('role', models.PositiveSmallIntegerField(choices=[(0, 'ADMIN'), (1, 'EDITOR'), (2, 'VIEWER')])),
                ('avatar_url', models.URLField()),
                ('unverified_phone_number', models.CharField(default=None, max_length=20, null=True)),
                ('_verified_phone_number', models.CharField(default=None, max_length=20, null=True)),
                ('is_active', models.BooleanField(default=True, null=True)),
                ('current_team', models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, to='user_management.team')),
                ('notification', models.ManyToManyField(through='alerts.UserHasNotification', to='alerts.AlertGroup')),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='users', to='user_management.organization')),
                ('slack_user_identity', models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='users', to='slack.slackuseridentity')),
            ],
            options={
                'unique_together': {('user_id', 'organization', 'is_active')},
            },
        ),
        migrations.AddField(
            model_name='team',
            name='users',
            field=models.ManyToManyField(related_name='teams', to='user_management.User'),
        ),
        migrations.AddField(
            model_name='organization',
            name='maintenance_author',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='organization_maintenances_created', to='user_management.user'),
        ),
        migrations.AddField(
            model_name='organization',
            name='slack_team_identity',
            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='organizations', to='slack.slackteamidentity'),
        ),
        migrations.AlterUniqueTogether(
            name='organization',
            unique_together={('stack_id', 'org_id')},
        ),
    ]
