# Generated by Django 5.2.4 on 2025-08-18 09:02

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Multiplexor',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=50, unique=True)),
                ('ip', models.GenericIPAddressField(blank=True, null=True)),
                ('subnet', models.GenericIPAddressField(blank=True, null=True)),
                ('gateway', models.GenericIPAddressField(blank=True, null=True)),
                ('sd_path', models.CharField(blank=True, max_length=255, null=True)),
            ],
        ),
        migrations.CreateModel(
            name='SensorType',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(max_length=10, unique=True)),
                ('name', models.CharField(max_length=100)),
                ('description', models.TextField(blank=True, null=True)),
                ('min_value', models.DecimalField(blank=True, decimal_places=4, max_digits=12, null=True)),
                ('max_value', models.DecimalField(blank=True, decimal_places=4, max_digits=12, null=True)),
            ],
        ),
        migrations.CreateModel(
            name='Channel',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('number', models.PositiveSmallIntegerField()),
                ('position', models.DecimalField(decimal_places=1, default=Decimal('1.0'), max_digits=4)),
                ('multiplexor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='channels', to='sitemanagement.multiplexor')),
            ],
            options={
                'unique_together': {('multiplexor', 'number', 'position')},
            },
        ),
        migrations.CreateModel(
            name='Sensor',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('serial_number', models.CharField(blank=True, max_length=50, null=True)),
                ('name', models.CharField(blank=True, max_length=50, null=True)),
                ('channel', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sensors', to='sitemanagement.channel')),
                ('sensor_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='sitemanagement.sensortype')),
            ],
        ),
        migrations.CreateModel(
            name='Metric',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('timestamp', models.DateTimeField()),
                ('raw_value', models.CharField(max_length=50)),
                ('value', models.FloatField(blank=True, null=True)),
                ('status', models.CharField(blank=True, max_length=20, null=True)),
                ('sensor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='metrics', to='sitemanagement.sensor')),
            ],
        ),
        migrations.CreateModel(
            name='Alert',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('message', models.CharField(max_length=255)),
                ('severity', models.CharField(choices=[('warning', 'Warning'), ('critical', 'Critical')], default='warning', max_length=20)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('resolved', models.BooleanField(default=False)),
                ('metric', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='alerts', to='sitemanagement.metric')),
                ('sensor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='alerts', to='sitemanagement.sensor')),
                ('sensor_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='alerts', to='sitemanagement.sensortype')),
            ],
        ),
        migrations.CreateModel(
            name='SignalFormat',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(max_length=50)),
                ('unit', models.CharField(blank=True, max_length=20, null=True)),
                ('conversion_rule', models.CharField(blank=True, max_length=255, null=True)),
                ('sensor_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='formats', to='sitemanagement.sensortype')),
            ],
        ),
        migrations.AddField(
            model_name='sensor',
            name='signal_format',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='sitemanagement.signalformat'),
        ),
        migrations.AddIndex(
            model_name='metric',
            index=models.Index(fields=['timestamp'], name='sitemanagem_timesta_ac22b7_idx'),
        ),
        migrations.AddIndex(
            model_name='metric',
            index=models.Index(fields=['sensor'], name='sitemanagem_sensor__8d94ff_idx'),
        ),
        migrations.AddIndex(
            model_name='alert',
            index=models.Index(fields=['created_at'], name='sitemanagem_created_3e8f3a_idx'),
        ),
        migrations.AddIndex(
            model_name='alert',
            index=models.Index(fields=['sensor'], name='sitemanagem_sensor__ef8d7b_idx'),
        ),
        migrations.AddIndex(
            model_name='alert',
            index=models.Index(fields=['sensor_type'], name='sitemanagem_sensor__a5f1eb_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='signalformat',
            unique_together={('sensor_type', 'code')},
        ),
    ]
