# Generated by Django 4.2.7 on 2025-09-19 02:19

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


class Migration(migrations.Migration):

    initial = True

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

    operations = [
        migrations.CreateModel(
            name='Report',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(max_length=255, verbose_name='报告标题')),
                ('summary', models.TextField(blank=True, verbose_name='报告摘要')),
                ('content', models.TextField(verbose_name='报告内容')),
                ('source_tag', models.CharField(blank=True, max_length=100, verbose_name='信息来源标签')),
                ('word_count', models.IntegerField(default=0, verbose_name='字数统计')),
                ('status', models.CharField(choices=[('generating', '生成中'), ('completed', '已完成'), ('failed', '失败')], default='generating', max_length=20, verbose_name='生成状态')),
                ('generated_at', models.DateTimeField(blank=True, null=True, verbose_name='生成完成时间')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
            ],
            options={
                'verbose_name': '报告',
                'verbose_name_plural': '报告',
                'db_table': 'reports',
                'ordering': ['-generated_at', '-created_at'],
            },
        ),
        migrations.CreateModel(
            name='Task',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(max_length=255, verbose_name='任务标题')),
                ('description', models.TextField(blank=True, verbose_name='任务描述')),
                ('requirement', models.TextField(verbose_name='用户需求描述')),
                ('type', models.CharField(choices=[('single', '单次任务'), ('scheduled', '周期任务')], max_length=20, verbose_name='任务类型')),
                ('status', models.CharField(choices=[('generating', '生成中'), ('running', '运行中'), ('paused', '暂停'), ('error', '异常'), ('completed', '已完成')], default='generating', max_length=20, verbose_name='任务状态')),
                ('schedule_config', models.JSONField(blank=True, null=True, verbose_name='周期任务配置')),
                ('sources_config', models.JSONField(default=dict, verbose_name='信息源配置')),
                ('web_search_enabled', models.BooleanField(default=True, verbose_name='是否启用联网搜索')),
                ('last_report_time', models.DateTimeField(blank=True, null=True, verbose_name='最新报告生成时间')),
                ('next_run_time', models.DateTimeField(blank=True, null=True, verbose_name='下次执行时间')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='用户')),
            ],
            options={
                'verbose_name': '任务',
                'verbose_name_plural': '任务',
                'db_table': 'tasks',
                'ordering': ['-last_report_time', '-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ReportSource',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('source_type', models.CharField(choices=[('wechat', '微信'), ('official-account', '公众号'), ('feishu', '飞书'), ('dingtalk', '钉钉'), ('email', '邮箱'), ('website', '网页'), ('baidu-pan', '百度网盘'), ('web-search', '联网搜索')], max_length=20, verbose_name='信息源类型')),
                ('source_name', models.CharField(max_length=255, verbose_name='信息源名称')),
                ('source_url', models.URLField(blank=True, verbose_name='原始链接')),
                ('raw_content', models.TextField(blank=True, verbose_name='原始内容')),
                ('extracted_content', models.TextField(blank=True, verbose_name='提取的关键内容')),
                ('collected_at', models.DateTimeField(auto_now_add=True, verbose_name='采集时间')),
                ('report', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sources', to='tasks.report', verbose_name='报告')),
            ],
            options={
                'verbose_name': '报告来源数据',
                'verbose_name_plural': '报告来源数据',
                'db_table': 'report_sources',
            },
        ),
        migrations.AddField(
            model_name='report',
            name='task',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reports', to='tasks.task', verbose_name='任务'),
        ),
        migrations.CreateModel(
            name='TaskLog',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('action_type', models.CharField(choices=[('created', '创建'), ('started', '开始'), ('paused', '暂停'), ('resumed', '恢复'), ('completed', '完成'), ('error', '错误')], max_length=20, verbose_name='操作类型')),
                ('message', models.TextField(blank=True, verbose_name='日志信息')),
                ('error_details', models.JSONField(blank=True, null=True, verbose_name='错误详情')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('task', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='logs', to='tasks.task', verbose_name='任务')),
            ],
            options={
                'verbose_name': '任务执行日志',
                'verbose_name_plural': '任务执行日志',
                'db_table': 'task_logs',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['task', 'created_at'], name='task_logs_task_id_e5a91c_idx'), models.Index(fields=['action_type'], name='task_logs_action__459c46_idx')],
            },
        ),
        migrations.AddIndex(
            model_name='task',
            index=models.Index(fields=['user', 'status'], name='tasks_user_id_a53e17_idx'),
        ),
        migrations.AddIndex(
            model_name='task',
            index=models.Index(fields=['last_report_time'], name='tasks_last_re_0965d4_idx'),
        ),
        migrations.AddIndex(
            model_name='task',
            index=models.Index(fields=['status'], name='tasks_status_031d4c_idx'),
        ),
        migrations.AddIndex(
            model_name='reportsource',
            index=models.Index(fields=['report'], name='report_sour_report__67ea05_idx'),
        ),
        migrations.AddIndex(
            model_name='reportsource',
            index=models.Index(fields=['source_type'], name='report_sour_source__1d8840_idx'),
        ),
        migrations.AddIndex(
            model_name='report',
            index=models.Index(fields=['task', 'generated_at'], name='reports_task_id_ff8229_idx'),
        ),
        migrations.AddIndex(
            model_name='report',
            index=models.Index(fields=['status'], name='reports_status_e83c1d_idx'),
        ),
        migrations.AddIndex(
            model_name='report',
            index=models.Index(fields=['generated_at'], name='reports_generat_a38578_idx'),
        ),
    ]
