from sqlalchemy import (
    JSON,
    Boolean,
    Column,
    DateTime,
    Integer,
    String,
    func,
)
from .database import Base


class Blog(Base):
    __tablename__ = "blogs"

    id = Column(Integer, primary_key=True, index=True)
    title = Column(String, index=True)
    author_id = Column(Integer, nullable=False, index=True)
    author_name = Column(String, nullable=False, index=True)
    description = Column(String, nullable=True)
    body = Column(String, nullable=False)
    created_at = Column(
        DateTime(timezone=True), server_default=func.now(), nullable=False
    )
    updated_at = Column(DateTime(timezone=True), onupdate=func.now())
    published_at = Column(DateTime(timezone=True), nullable=True)

    # Document Meta Data
    word_count = Column(Integer, nullable=True)
    version = Column(Integer, nullable=True)
    read_time = Column(Integer, nullable=True)
    language = Column(String, nullable=True)
    tags = Column(JSON, nullable=True)

    # User Meta Data
    view_count = Column(Integer, default=0, nullable=False)
    like_count = Column(Integer, default=0, nullable=False)


class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, index=True)
    username = Column(String, unique=True, nullable=False, index=True)
    email = Column(String, unique=True, nullable=False, index=True)
    hashed_password = Column(String, nullable=False)
    permissions = Column(JSON, nullable=False)
    subscriber = Column(Boolean, nullable=False)
