from sqlalchemy import Column, String, Integer, Boolean, DateTime, ForeignKey
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.sql import func
import uuid
# JAVÍTVA: Közvetlenül a base_class-ból importálunk, nem a base-ből!
from app.db.base_class import Base

class Document(Base):
    __tablename__ = "documents"
    __table_args__ = {"schema": "data"}

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    parent_type = Column(String(20), nullable=False) # 'organization' vagy 'asset'
    parent_id = Column(String(50), nullable=False)   # Org vagy Asset technikai ID-ja
    doc_type = Column(String(50))                    # pl. 'foundation_deed', 'registration'
    
    original_name = Column(String(255), nullable=False)
    file_hash = Column(String(64), nullable=False)   # A NAS-on tárolt név (UUID)
    file_ext = Column(String(10), default="webp")
    mime_type = Column(String(100), default="image/webp")
    file_size = Column(Integer)
    
    has_thumbnail = Column(Boolean, default=False)
    thumbnail_path = Column(String(255)) # SSD-n lévő elérés
    
    uploaded_by = Column(Integer, ForeignKey("data.users.id"), nullable=True)
    created_at = Column(DateTime(timezone=True), server_default=func.now())