"""主题设置模型 — 每租户一条记录"""
from sqlalchemy import BigInteger, ForeignKey, UniqueConstraint, JSON
from sqlalchemy.orm import Mapped, mapped_column

from app.core.models.base import Base, TimestampMixin


class ThemeSettings(Base, TimestampMixin):
    __tablename__ = "theme_settings"
    __table_args__ = (
        UniqueConstraint("tenant_id", name="uk_theme_settings_tenant"),
        {
            "mysql_engine": "InnoDB",
            "mysql_charset": "utf8mb4",
            "mysql_collate": "utf8mb4_unicode_ci",
        },
    )

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
    tenant_id: Mapped[int] = mapped_column(
        BigInteger,
        ForeignKey("tenants.id", ondelete="CASCADE"),
        nullable=False,
        unique=True,
        comment="租户 ID",
    )
    settings: Mapped[dict | None] = mapped_column(JSON, nullable=True, comment="主题配置 JSON")
