"""
公共抽象模型。所有业务页面应继承 SEOablePage 而非直接继承 wagtail.models.Page，
以统一获得 SEO 字段（详见 documents/设计方案分析与完善版.md §2.5）。
"""
from django.db import models
from wagtail.admin.panels import FieldPanel
from wagtail.models import Page


class SEOablePage(Page):
    seo_title_override = models.CharField(
        max_length=70, blank=True, verbose_name="SEO 标题",
        help_text="留空则使用页面标题",
    )
    seo_description_override = models.CharField(
        max_length=160, blank=True, verbose_name="SEO 描述",
    )
    og_image = models.ForeignKey(
        "wagtailimages.Image",
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="+",
        verbose_name="社交分享图",
    )
    canonical_url = models.URLField(blank=True, verbose_name="Canonical URL")
    schema_json = models.JSONField(blank=True, default=dict, verbose_name="结构化数据 (JSON-LD)")

    promote_panels = Page.promote_panels + [
        FieldPanel("seo_title_override"),
        FieldPanel("seo_description_override"),
        FieldPanel("og_image"),
        FieldPanel("canonical_url"),
        FieldPanel("schema_json"),
    ]

    class Meta:
        abstract = True
