# Generated by Django 4.1.13 on 2026-03-18 00:00

import common.db.fields
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('users', '0004_fix_user_wechat_phone'),
    ]

    operations = [
        migrations.CreateModel(
            name='Report',
            fields=[
                ('created_by', models.CharField(blank=True, max_length=128, null=True, verbose_name='Created by')),
                ('updated_by', models.CharField(blank=True, max_length=128, null=True, verbose_name='Updated by')),
                ('date_created', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Date created')),
                ('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
                ('comment', models.TextField(blank=True, default='', verbose_name='Comment')),
                ('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
                ('org_id', models.CharField(blank=True, db_index=True, default='', max_length=36, verbose_name='Organization')),
                ('name', models.CharField(max_length=128, verbose_name='Name')),
                ('is_periodic', models.BooleanField(default=False, verbose_name='Periodic run')),
                ('interval', models.IntegerField(blank=True, default=24, null=True, verbose_name='Interval')),
                ('crontab', models.CharField(blank=True, default='', max_length=128, verbose_name='Crontab')),
                ('start_time', models.DateTimeField(blank=True, help_text='Datetime when the schedule should begin triggering the task to run', null=True, verbose_name='Start Datetime')),
                ('date_last_run', models.DateTimeField(blank=True, null=True, verbose_name='Date last run')),
                ('tp', models.CharField(max_length=64, verbose_name='Type')),
                ('is_builtin', models.BooleanField(default=False, verbose_name='Is builtin')),
                ('is_active', models.BooleanField(default=True, verbose_name='Is active')),
                ('range_days', models.PositiveIntegerField(default=7, verbose_name='Range days')),
                ('filters', models.JSONField(default=dict, verbose_name='Filters')),
                ('recipients', common.db.fields.JSONManyToManyField(default=dict, to='users.User', verbose_name='Recipients')),
            ],
            options={
                'verbose_name': 'Report',
                'ordering': ['-date_created'],
                'unique_together': {('org_id', 'name')},
            },
        ),
        migrations.CreateModel(
            name='ReportExecution',
            fields=[
                ('org_id', models.CharField(blank=True, db_index=True, default='', max_length=36, verbose_name='Organization')),
                ('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('running', 'Running'), ('success', 'Success'), ('failed', 'Failed')], default='pending', max_length=16)),
                ('date_created', models.DateTimeField(auto_now_add=True)),
                ('date_start', models.DateTimeField(db_index=True, null=True)),
                ('date_finished', models.DateTimeField(null=True)),
                ('duration', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('trigger', models.CharField(choices=[('manual', 'Manual'), ('timing', 'Timing')], default='manual', max_length=128)),
                ('snapshot', models.JSONField(default=dict)),
                ('summary', models.JSONField(default=dict)),
                ('report', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='executions', to='reports.report')),
            ],
            options={
                'ordering': ('org_id', '-date_start'),
            },
        ),
        migrations.CreateModel(
            name='ReportSendRecord',
            fields=[
                ('created_by', models.CharField(blank=True, max_length=128, null=True, verbose_name='Created by')),
                ('updated_by', models.CharField(blank=True, max_length=128, null=True, verbose_name='Updated by')),
                ('date_created', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Date created')),
                ('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
                ('comment', models.TextField(blank=True, default='', verbose_name='Comment')),
                ('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
                ('org_id', models.CharField(blank=True, db_index=True, default='', max_length=36, verbose_name='Organization')),
                ('backend', models.CharField(blank=True, default='', max_length=32)),
                ('receiver', models.CharField(blank=True, default='', max_length=128)),
                ('report_url', models.TextField(blank=True, default='')),
                ('is_success', models.BooleanField(default=True)),
                ('error', models.TextField(blank=True, default='')),
                ('detail', models.TextField(blank=True, default='')),
                ('execution', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='send_records', to='reports.reportexecution')),
            ],
            options={
                'ordering': ['-date_created'],
            },
        ),
    ]