# Generated by Django 4.2.30 on 2026-05-22 07:35

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Client',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('nom', models.CharField(max_length=200)),
                ('adresse', models.TextField()),
                ('telephone', models.CharField(max_length=20)),
                ('email', models.EmailField(max_length=254)),
            ],
        ),
        migrations.CreateModel(
            name='ControleResultat',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('statut', models.CharField(choices=[('CONFORME', 'Conforme'), ('NON_CONFORME', 'Non conforme'), ('SUSPENDU', 'Suspendu')], max_length=20)),
                ('observation', models.TextField(blank=True)),
                ('date_controle', models.DateTimeField(auto_now_add=True)),
            ],
        ),
        migrations.CreateModel(
            name='ElementOuvrage',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(max_length=50)),
                ('nom', models.CharField(max_length=200)),
                ('description', models.TextField(blank=True)),
            ],
        ),
        migrations.CreateModel(
            name='Ouvrage',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(max_length=50, unique=True)),
                ('nom', models.CharField(max_length=200)),
                ('description', models.TextField(blank=True)),
                ('est_actif', models.BooleanField(default=True)),
            ],
        ),
        migrations.CreateModel(
            name='ProcesVerbal',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('numero', models.CharField(max_length=50, unique=True)),
                ('date_visite', models.DateTimeField()),
                ('lieu', models.CharField(max_length=200)),
                ('observations_generales', models.TextField(blank=True)),
                ('date_creation', models.DateTimeField(auto_now_add=True)),
                ('date_modification', models.DateTimeField(auto_now=True)),
                ('emails_envoyes', models.TextField(blank=True, help_text='Emails séparés par des virgules')),
                ('date_envoi', models.DateTimeField(blank=True, null=True)),
                ('client', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='controle_app.client')),
                ('createur', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Procès-verbal',
                'verbose_name_plural': 'Procès-verbaux',
                'ordering': ['-date_visite'],
            },
        ),
        migrations.CreateModel(
            name='TypePV',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('type_pv', models.CharField(choices=[('RECEPTION', 'Procès-verbal de réception'), ('CONSTAT', 'Procès-verbal de constat'), ('CONTROLE', 'Procès-verbal de visite de contrôle'), ('MISE_SERVICE', 'Procès-verbal de mise en service'), ('LEVER_RESERVES', 'Procès-verbal de lever de réserves')], default='CONTROLE', max_length=50)),
                ('code', models.CharField(max_length=20, unique=True)),
            ],
        ),
        migrations.CreateModel(
            name='Recommandation',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('texte', models.TextField()),
                ('ordre', models.IntegerField(default=0)),
                ('proces_verbal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='recommandations', to='controle_app.procesverbal')),
            ],
            options={
                'ordering': ['ordre'],
            },
        ),
        migrations.CreateModel(
            name='Projets',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('nom_projet', models.CharField(blank=True, max_length=200, null=True)),
                ('adresse', models.CharField(max_length=200)),
                ('etat', models.CharField(choices=[('EN_COURS', 'En cours'), ('ARRETE', 'Arrêté'), ('TERMINE', 'Terminé')], default='EN_COURS', max_length=20)),
                ('client', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='projets', to='controle_app.client')),
            ],
        ),
        migrations.AddField(
            model_name='procesverbal',
            name='objet_controle',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='controle_app.projets'),
        ),
        migrations.AddField(
            model_name='procesverbal',
            name='type_pv',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='controle_app.typepv'),
        ),
        migrations.CreateModel(
            name='PointControle',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(blank=True, max_length=50, null=True)),
                ('point_de_controle', models.CharField(blank=True, max_length=200, null=True)),
                ('element', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='points_controle', to='controle_app.elementouvrage')),
            ],
        ),
        migrations.CreateModel(
            name='Photo',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('image', models.ImageField(upload_to='photos/')),
                ('legende', models.CharField(blank=True, max_length=200)),
                ('date_prise', models.DateTimeField(default=django.utils.timezone.now)),
                ('controle', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='photos', to='controle_app.controleresultat')),
            ],
        ),
        migrations.CreateModel(
            name='Participant',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('nom', models.CharField(max_length=200)),
                ('fonction', models.CharField(blank=True, max_length=200)),
                ('organisme', models.CharField(blank=True, max_length=200)),
                ('signature', models.TextField(blank=True, null=True)),
                ('date_signature', models.DateTimeField(auto_now_add=True, null=True)),
                ('pv', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='participants', to='controle_app.procesverbal')),
            ],
            options={
                'verbose_name': 'Participant',
                'verbose_name_plural': 'Participants',
            },
        ),
        migrations.AddField(
            model_name='elementouvrage',
            name='ouvrage',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='elements', to='controle_app.ouvrage'),
        ),
        migrations.AddField(
            model_name='controleresultat',
            name='point_controle',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='resultats', to='controle_app.pointcontrole'),
        ),
        migrations.AddField(
            model_name='controleresultat',
            name='pv',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='controles', to='controle_app.procesverbal'),
        ),
        migrations.AlterUniqueTogether(
            name='controleresultat',
            unique_together={('pv', 'point_controle')},
        ),
    ]
