from pydantic_settings import BaseSettings, SettingsConfigDict


class NatsCommonSettings(BaseSettings):
    """
    Base Settings for NATS components.

    You can adapt the following settings in your environment variables (or using and .env file):
    - NATS_URL: The URL of the NATS server
    - NATS_SUBJECT_PREFIX: The prefix of the NATS subjects (optional)
    - NATS_DEVICE: The device of the NATS server (optional)

    The subject prefix is added in front of all subjects.
    The device is appended to the subject prefix.

    Example:
    - NATS_URL=nats://localhost:4222
    - NATS_SUBJECT_PREFIX=test.foo
    - NATS_DEVICE=device1
    """

    model_config = SettingsConfigDict(
        env_file=".env",
        env_file_encoding="utf-8",
        env_prefix="NATS_",
        env_nested_delimiter="__",
        extra="ignore",
    )

    # NATS URL
    url: str = "nats://localhost:4222"

    # NATS subject prefix added in front of all subjects
    subject_prefix: str | None = None

    # Optional device appended to the subject prefix
    device: str | None = None


if __name__ == "__main__":
    settings = NatsCommonSettings()
    print(settings.model_dump_json())
