# Generated by Django 3.2.14 on 2022-09-07 13:50

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


class Migration(migrations.Migration):

    dependencies = [
        ('orgs', '0023_auto_20220721_1851'),
        ('seed', '0176_dataview_dataviewparameter'),
    ]

    operations = [
        migrations.CreateModel(
            name='ComplianceMetric',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=255)),
                ('start', models.DateTimeField()),
                ('end', models.DateTimeField()),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('energy_metric_type', models.IntegerField(choices=[(0, 'Target > Actual for Compliance'), (1, 'Actual > Target for Compliance')], default=0)),
                ('emission_metric_type', models.IntegerField(choices=[(0, 'Target > Actual for Compliance'), (1, 'Actual > Target for Compliance')], default=0)),
                ('actual_emission_column', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='actual_emission_column', to='seed.column')),
                ('actual_energy_column', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='actual_energy_column', to='seed.column')),
                ('organization', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='compliance_metrics', to='orgs.organization')),
                ('target_emission_column', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='target_emission_column', to='seed.column')),
                ('target_energy_column', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='target_energy_column', to='seed.column')),
                ('x_axis_columns', models.ManyToManyField(related_name='x_axis_columns', to='seed.Column')),
            ],
            options={
                'ordering': ['-created'],
                'get_latest_by': 'created',
            },
        ),
        migrations.AddConstraint(
            model_name='compliancemetric',
            constraint=models.CheckConstraint(check=models.Q(('actual_energy_column__isnull', False), ('actual_emission_column__isnull', False), _connector='OR'), name='at_least_one_compliance_metric_type'),
        ),
    ]
