from django_filters import rest_framework as filters
from .models import Paper


class PaperFilterSet(filters.FilterSet):
    # 年份范围(LLM 做"近 N 年文献"很常见)
    publication_year_gte = filters.NumberFilter(field_name="publication_year", lookup_expr="gte")
    publication_year_lte = filters.NumberFilter(field_name="publication_year", lookup_expr="lte")

    # 发表日期范围(比 year 更细,支持 YYYY-MM-DD)
    publication_date_gte = filters.DateFilter(field_name="publication_date", lookup_expr="gte")
    publication_date_lte = filters.DateFilter(field_name="publication_date", lookup_expr="lte")

    class Meta:
        model = Paper
        fields = [
            # 原有
            "publication_year",
            "publication_date",   # 精确日期 YYYY-MM-DD
            "type",
            "fetch_status",
            "has_abstract",
            "has_fulltext",
            "doi",
            # 新增
            "has_fulltext_pdf",   # 比 has_fulltext 更准:zcbot research skill 的 has_pdf 参数走这个
            "is_oa",              # 是否开放获取
            "publication_name",   # 期刊精确名
            "first_author",       # 作者精确名
            "openalex_id",        # OpenAlex 唯一标识(等价 doi)
        ]
