from sqlalchemy import Integer, String, Text, DateTime, BigInteger, JSON
from sqlalchemy.orm import Mapped, mapped_column
from app.core.models.base import Base, TimestampMixin
from datetime import datetime
from typing import Optional


class Article(Base, TimestampMixin):
    __tablename__ = "articles"

    id:              Mapped[int]           = mapped_column(Integer, primary_key=True, index=True, autoincrement=True)
    tenant_id:       Mapped[int]           = mapped_column(BigInteger, nullable=False, index=True)
    title:           Mapped[str]           = mapped_column(String(255), nullable=False)
    title_en:        Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
    slug:            Mapped[str]           = mapped_column(String(255), nullable=False, index=True)
    content:         Mapped[Optional[str]] = mapped_column(Text, nullable=True)
    content_en:      Mapped[Optional[str]] = mapped_column(Text, nullable=True)
    excerpt:         Mapped[Optional[str]] = mapped_column(Text, nullable=True)
    excerpt_en:      Mapped[Optional[str]] = mapped_column(Text, nullable=True)
    featured_image:  Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
    status:          Mapped[str]           = mapped_column(String(20), nullable=False, default="draft")
    author_name:     Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
    published_at:    Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
    view_count:      Mapped[int]           = mapped_column(Integer, default=0)

    # SEO
    seo_title:           Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
    seo_title_en:        Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
    seo_description:     Mapped[Optional[str]] = mapped_column(Text, nullable=True)
    seo_description_en:  Mapped[Optional[str]] = mapped_column(Text, nullable=True)
    seo_keywords:        Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
    seo_keywords_en:     Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
    og_image:            Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
    canonical_url:       Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
    content_blocks:      Mapped[Optional[list]] = mapped_column(JSON, nullable=True)
    preview_token:       Mapped[Optional[str]]  = mapped_column(String(64), nullable=True, unique=True)
