from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, Boolean
from sqlalchemy.sql import func
from app.db.base import Base

class LegalDocument(Base):
    __tablename__ = "legal_documents"
    __table_args__ = {"schema": "data"}

    id = Column(Integer, primary_key=True, index=True)
    title = Column(String(255))
    content = Column(Text, nullable=False)
    version = Column(String(20), nullable=False)
    
    region_code = Column(String(5), default="HU")
    language = Column(String(5), default="hu")
    
    is_active = Column(Boolean, default=True)
    created_at = Column(DateTime(timezone=True), server_default=func.now())

class LegalAcceptance(Base):
    __tablename__ = "legal_acceptances"
    __table_args__ = {"schema": "data"}

    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, ForeignKey("data.users.id"))
    document_id = Column(Integer, ForeignKey("data.legal_documents.id"))
    accepted_at = Column(DateTime(timezone=True), server_default=func.now())
    ip_address = Column(String(45))
    user_agent = Column(Text)
