"""SystemConfig model — runtime key-value configuration store."""

import uuid

from sqlalchemy import Column, String, Text, DateTime, func
from sqlalchemy.dialects.postgresql import UUID

from app.database import Base


class SystemConfig(Base):
    """Generic key-value store for runtime system configuration.

    Currently used for:
    - SMTP email settings (overrides .env values when present)

    Keys are namespaced by convention: ``smtp.host``, ``smtp.port``, etc.
    """

    __tablename__ = "system_configs"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    key = Column(String(200), unique=True, nullable=False, index=True)
    value = Column(Text, nullable=True)
    description = Column(String(500), nullable=True)
    updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
