# backend/app/models/system.py import enum from sqlalchemy import Column, String, DateTime, Boolean, text, UniqueConstraint, Integer from sqlalchemy.dialects.postgresql import JSONB # <-- JSONB-t használunk a stabilitásért from sqlalchemy.sql import func from app.db.base_class import Base class SystemParameter(Base): """ Központi, dinamikus konfigurációs tábla. Támogatja a többlépcsős felülbírálást (Global -> Country -> Region -> Individual). """ __tablename__ = "system_parameters" __table_args__ = ( UniqueConstraint('key', 'scope_level', 'scope_id', name='uix_param_scope'), {"schema": "data", "extend_existing": True} ) # Technikai ID, hogy a 'key' ne legyen Primary Key, így engedve a hierarchiát id = Column(Integer, primary_key=True, autoincrement=True) key = Column(String, index=True, nullable=False) # pl. 'VEHICLE_LIMIT' category = Column(String, index=True, server_default="general") # A tényleges érték (JSONB-ben tárolva) value = Column(JSONB, nullable=False) # pl. {"FREE": 1, "PREMIUM": 4} # --- 🛡️ HIERARCHIKUS SZINTEK --- scope_level = Column(String(30), server_default=text("'global'"), index=True) scope_id = Column(String(50), nullable=True) is_active = Column(Boolean, default=True) description = Column(String) last_modified_by = Column(String, nullable=True) updated_at = Column(DateTime(timezone=True), onupdate=func.now(), server_default=func.now())