# Generated by Django 5.2.9 on 2026-01-01 02:34

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


class Migration(migrations.Migration):

    dependencies = [
        ("policy", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="PolicyLevelKeywordModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "level",
                    models.CharField(
                        choices=[
                            ("P0", "P0 - 常态"),
                            ("P1", "P1 - 预警"),
                            ("P2", "P2 - 干预"),
                            ("P3", "P3 - 危机"),
                        ],
                        max_length=2,
                        verbose_name="政策档位",
                    ),
                ),
                (
                    "keywords",
                    models.JSONField(
                        help_text="JSON数组格式的关键词列表", verbose_name="关键词列表"
                    ),
                ),
                ("weight", models.IntegerField(default=1, verbose_name="权重")),
                (
                    "category",
                    models.CharField(
                        blank=True,
                        help_text="留空表示适用于所有RSS源分类",
                        max_length=50,
                        null=True,
                        verbose_name="适用分类",
                    ),
                ),
                ("is_active", models.BooleanField(default=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": "policy_level_keywords",
                "ordering": ["-weight", "level"],
                "indexes": [
                    models.Index(
                        fields=["is_active", "level"], name="policy_leve_is_acti_8afd49_idx"
                    ),
                    models.Index(fields=["category"], name="policy_leve_categor_e1a0d9_idx"),
                ],
            },
        ),
        migrations.CreateModel(
            name="RSSSourceConfigModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("name", models.CharField(max_length=100, unique=True, verbose_name="源名称")),
                ("url", models.URLField(max_length=500, verbose_name="RSS URL")),
                (
                    "category",
                    models.CharField(
                        choices=[
                            ("gov_docs", "政府文件库"),
                            ("central_bank", "央行公告"),
                            ("mof", "财政部"),
                            ("csrc", "证监会"),
                            ("media", "财经媒体"),
                            ("other", "其他"),
                        ],
                        default="other",
                        max_length=20,
                        verbose_name="分类",
                    ),
                ),
                ("is_active", models.BooleanField(default=True, verbose_name="是否启用")),
                (
                    "fetch_interval_hours",
                    models.IntegerField(default=6, verbose_name="抓取间隔(小时)"),
                ),
                (
                    "extract_content",
                    models.BooleanField(
                        default=False,
                        help_text="是否从RSS链接中提取文章正文内容",
                        verbose_name="提取完整内容",
                    ),
                ),
                ("proxy_enabled", models.BooleanField(default=False, verbose_name="启用代理")),
                (
                    "proxy_host",
                    models.CharField(blank=True, max_length=200, verbose_name="代理主机"),
                ),
                ("proxy_port", models.IntegerField(blank=True, null=True, verbose_name="代理端口")),
                (
                    "proxy_username",
                    models.CharField(blank=True, max_length=100, verbose_name="代理用户名"),
                ),
                (
                    "proxy_password",
                    models.CharField(blank=True, max_length=200, verbose_name="代理密码"),
                ),
                (
                    "proxy_type",
                    models.CharField(
                        choices=[("http", "HTTP"), ("https", "HTTPS"), ("socks5", "SOCKS5")],
                        default="http",
                        max_length=10,
                        verbose_name="代理类型",
                    ),
                ),
                (
                    "parser_type",
                    models.CharField(
                        choices=[("feedparser", "feedparser"), ("httpx", "httpx+manual")],
                        default="feedparser",
                        max_length=20,
                        verbose_name="解析器类型",
                    ),
                ),
                ("timeout_seconds", models.IntegerField(default=30, verbose_name="超时时间(秒)")),
                ("retry_times", models.IntegerField(default=3, verbose_name="重试次数")),
                (
                    "last_fetch_at",
                    models.DateTimeField(blank=True, null=True, verbose_name="最后抓取时间"),
                ),
                (
                    "last_fetch_status",
                    models.CharField(blank=True, max_length=20, verbose_name="最后抓取状态"),
                ),
                ("last_error_message", models.TextField(blank=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": "RSS源配置",
                "verbose_name_plural": "RSS源配置",
                "db_table": "rss_source_config",
                "ordering": ["category", "name"],
                "indexes": [
                    models.Index(
                        fields=["is_active", "category"], name="rss_source__is_acti_6fe709_idx"
                    )
                ],
            },
        ),
        migrations.CreateModel(
            name="RSSFetchLog",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "fetched_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, verbose_name="抓取时间"),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[("success", "成功"), ("error", "失败"), ("partial", "部分成功")],
                        max_length=20,
                        verbose_name="状态",
                    ),
                ),
                ("items_count", models.IntegerField(default=0, verbose_name="条目总数")),
                ("new_items_count", models.IntegerField(default=0, verbose_name="新增条目数")),
                ("error_message", models.TextField(blank=True, verbose_name="错误信息")),
                (
                    "fetch_duration_seconds",
                    models.FloatField(blank=True, null=True, verbose_name="耗时(秒)"),
                ),
                (
                    "source",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="fetch_logs",
                        to="policy.rsssourceconfigmodel",
                        verbose_name="RSS源",
                    ),
                ),
            ],
            options={
                "verbose_name": "RSS抓取日志",
                "verbose_name_plural": "RSS抓取日志",
                "db_table": "rss_fetch_log",
                "ordering": ["-fetched_at"],
                "indexes": [
                    models.Index(fields=["-fetched_at"], name="rss_fetch_l_fetched_f8b96c_idx"),
                    models.Index(
                        fields=["source", "status"], name="rss_fetch_l_source__9edf29_idx"
                    ),
                ],
            },
        ),
    ]
