# Generated by Django 6.0.1 on 2026-05-11 20:32

import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('organizations', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='ReportTemplate',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=200)),
                ('description', models.TextField(blank=True)),
                ('category', models.CharField(blank=True, max_length=100)),
                ('data_source', models.CharField(choices=[('complaints', 'Complaints'), ('inquiries', 'Inquiries'), ('observations', 'Observations'), ('px_actions', 'PX Actions'), ('surveys', 'Surveys'), ('physicians', 'Physician Ratings')], default='complaints', max_length=50)),
                ('filter_config', models.JSONField(default=dict)),
                ('column_config', models.JSONField(default=list)),
                ('grouping_config', models.JSONField(default=dict)),
                ('sort_config', models.JSONField(default=list)),
                ('chart_config', models.JSONField(default=dict)),
                ('icon', models.CharField(blank=True, help_text='Bootstrap icon class', max_length=50)),
                ('sort_order', models.IntegerField(default=0)),
                ('is_active', models.BooleanField(default=True)),
            ],
            options={
                'ordering': ['sort_order', 'name'],
            },
        ),
        migrations.CreateModel(
            name='SavedReport',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=200)),
                ('description', models.TextField(blank=True)),
                ('data_source', models.CharField(choices=[('complaints', 'Complaints'), ('inquiries', 'Inquiries'), ('observations', 'Observations'), ('px_actions', 'PX Actions'), ('surveys', 'Surveys'), ('physicians', 'Physician Ratings')], default='complaints', max_length=50)),
                ('filter_config', models.JSONField(blank=True, default=dict)),
                ('column_config', models.JSONField(blank=True, default=list)),
                ('grouping_config', models.JSONField(blank=True, default=dict)),
                ('sort_config', models.JSONField(blank=True, default=list)),
                ('chart_config', models.JSONField(blank=True, default=dict)),
                ('is_shared', models.BooleanField(default=False, help_text='Share with other users in the same hospital')),
                ('is_template', models.BooleanField(default=False, help_text='Available as a template for others to use')),
                ('last_run_at', models.DateTimeField(blank=True, null=True)),
                ('last_run_count', models.IntegerField(default=0)),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='saved_reports', to=settings.AUTH_USER_MODEL)),
                ('hospital', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='saved_reports', to='organizations.hospital')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ReportSchedule',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('frequency', models.CharField(choices=[('once', 'One Time'), ('daily', 'Daily'), ('weekly', 'Weekly'), ('monthly', 'Monthly'), ('quarterly', 'Quarterly')], default='weekly', max_length=20)),
                ('delivery_time', models.CharField(default='09:00', help_text='Time to send report (HH:MM format)', max_length=5)),
                ('day_of_week', models.IntegerField(blank=True, help_text='For weekly reports: 0=Monday, 6=Sunday', null=True)),
                ('day_of_month', models.IntegerField(blank=True, help_text='For monthly reports: 1-31', null=True)),
                ('export_format', models.CharField(choices=[('html', 'View Online'), ('pdf', 'PDF'), ('excel', 'Excel'), ('csv', 'CSV')], default='pdf', max_length=20)),
                ('recipients', models.JSONField(default=list, help_text='List of email addresses to receive the report')),
                ('is_active', models.BooleanField(default=True)),
                ('last_run_at', models.DateTimeField(blank=True, null=True)),
                ('next_run_at', models.DateTimeField(blank=True, null=True)),
                ('last_error', models.TextField(blank=True)),
                ('report', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='schedules', to='reports.savedreport')),
            ],
            options={
                'ordering': ['next_run_at'],
            },
        ),
        migrations.CreateModel(
            name='GeneratedReport',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=200)),
                ('data_source', models.CharField(choices=[('complaints', 'Complaints'), ('inquiries', 'Inquiries'), ('observations', 'Observations'), ('px_actions', 'PX Actions'), ('surveys', 'Surveys'), ('physicians', 'Physician Ratings')], max_length=50)),
                ('filter_config', models.JSONField(default=dict)),
                ('column_config', models.JSONField(default=list)),
                ('grouping_config', models.JSONField(default=dict)),
                ('chart_config', models.JSONField(default=dict)),
                ('data', models.JSONField(default=dict, help_text='The actual report data')),
                ('summary', models.JSONField(default=dict, help_text='Summary statistics')),
                ('chart_data', models.JSONField(default=dict, help_text='Chart-formatted data')),
                ('row_count', models.IntegerField(default=0)),
                ('pdf_file', models.FileField(blank=True, null=True, upload_to='reports/pdf/')),
                ('excel_file', models.FileField(blank=True, null=True, upload_to='reports/excel/')),
                ('csv_file', models.FileField(blank=True, null=True, upload_to='reports/csv/')),
                ('expires_at', models.DateTimeField(blank=True, null=True)),
                ('generated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='generated_reports', to=settings.AUTH_USER_MODEL)),
                ('hospital', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='generated_reports', to='organizations.hospital')),
                ('saved_report', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='generated_reports', to='reports.savedreport')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddIndex(
            model_name='savedreport',
            index=models.Index(fields=['data_source', '-created_at'], name='reports_sav_data_so_d53f3a_idx'),
        ),
        migrations.AddIndex(
            model_name='savedreport',
            index=models.Index(fields=['created_by', '-created_at'], name='reports_sav_created_836da5_idx'),
        ),
        migrations.AddIndex(
            model_name='savedreport',
            index=models.Index(fields=['hospital', 'is_shared'], name='reports_sav_hospita_6b4af6_idx'),
        ),
        migrations.AddIndex(
            model_name='generatedreport',
            index=models.Index(fields=['data_source', '-created_at'], name='reports_gen_data_so_118c97_idx'),
        ),
        migrations.AddIndex(
            model_name='generatedreport',
            index=models.Index(fields=['generated_by', '-created_at'], name='reports_gen_generat_f13e26_idx'),
        ),
        migrations.AddIndex(
            model_name='generatedreport',
            index=models.Index(fields=['expires_at'], name='reports_gen_expires_a93554_idx'),
        ),
    ]
