from sqlalchemy import Integer, String, Boolean, Text, JSON
from sqlalchemy.orm import Mapped, mapped_column
from typing import Optional
from app.database import Base


class User(Base):
    __tablename__ = "users"

    id:Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
    username:Mapped[str] = mapped_column(String, unique=True, index=True, nullable=False)
    email:Mapped[str] = mapped_column(String, unique=True, index=True, nullable=False)
    hashed_password:Mapped[str] = mapped_column(String, nullable=False)
    is_active:Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
    is_admin:Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)


class Article(Base):
    __tablename__ = "articles"

    id:Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
    slug:Mapped[str] = mapped_column(String, unique=True, index=True, nullable=False)
    section:Mapped[str] = mapped_column(String, nullable=False)
    title:Mapped[str] = mapped_column(String, nullable=False)
    subtitle:Mapped[Optional[str]] = mapped_column(String, nullable=True)
    author:Mapped[Optional[str]] = mapped_column(String, nullable=True)
    date:Mapped[str] = mapped_column(String, nullable=False)
    tags:Mapped[list] = mapped_column(JSON, default=list)
    excerpt:Mapped[Optional[str]] = mapped_column(Text, nullable=True)
    cover_image:Mapped[Optional[str]] = mapped_column(String, nullable=True)
    inline_image:Mapped[Optional[str]] = mapped_column(String, nullable=True)  # Given that inline images are already handled by <img> tags inside the html column, the inline_image column is redundant for that purpose. It's likely meant for a single featured/secondary image separate from the cover; something like a pull quote image or a specific image you want to reference independently.
    body_html:Mapped[str] = mapped_column(Text, nullable=False)                # Full rendered article body as an HTML string — your API returns it, and the frontend just injects it into the page.
    markdown_path:Mapped[str] = mapped_column(String, nullable=False)          # If we decide to keep the Markdown file on the filesystem.
    views:Mapped[int] = mapped_column(Integer, default=0, nullable=False)
