import uuid
from datetime import datetime, timezone
from sqlalchemy import Column, String, Text, DateTime, Integer
from sqlalchemy.dialects.postgresql import UUID
from core.database import Base

class HelpArticle(Base):
    """
    Modelo para los artículos de ayuda (Base de Conocimientos).
    Sincronizado entre Servidor Central y Clientes.
    """
    __tablename__ = "help_articles"

    uuid = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, index=True)
    slug = Column(String(255), unique=True, index=True, nullable=False)
    title = Column(String(255), nullable=False)
    content = Column(Text, nullable=False)
    updated_at = Column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc), nullable=False)
    last_editor = Column(String(255), nullable=False)
    
    # Library Mode Fields
    category = Column(String(255), nullable=True, default="General")
    order = Column(Integer, nullable=True, default=0)
    
    # Removed missing fields to avoid 500 errors (No migration approach)
    # content_type = Column(String(50), nullable=False, default="article")
    # file_url = Column(String(512), nullable=True)
    # file_size = Column(Integer, nullable=True)
    # mime_type = Column(String(100), nullable=True)

    def __repr__(self):
        return f"<HelpArticle(title='{self.title}', slug='{self.slug}')>"
