from typing import Optional

from semantic_models.services.semantic_models_service import SemanticModelsService


def get_semantic_models_service(
    client: Optional[object] = None,
) -> SemanticModelsService:
    """
    Get SemanticModelsService instance.

    If no client is provided, creates one using the project key from AppConfig.
    """
    if client is None:
        from semantic_models.config import get_app_config
        from semantic_models.services.local_semantic_model_client import LocalSemanticModelClient

        config = get_app_config()
        client = LocalSemanticModelClient(config.dss_project_key)
    return SemanticModelsService(client=client)
