# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Utilities for Output Schema.

This module is for ADK internal use only.
Please do not rely on the implementation details.
"""

from __future__ import annotations

from typing import Union

from ..models.base_llm import BaseLlm
from .model_name_utils import is_gemini_eap_or_2_or_above
from .variant_utils import get_google_llm_variant
from .variant_utils import GoogleLLMVariant


def can_use_output_schema_with_tools(model: Union[str, BaseLlm]) -> bool:
  """Returns True if output schema with tools is supported."""
  # LiteLLM handles tools + response_format compatibility per-provider:
  # - Providers with native support (OpenAI, Azure): both passed directly
  # - Providers without (Fireworks): auto-converted to json_tool_call +
  #   tool_choice enforcement
  # This is strictly more reliable than the SetModelResponseTool
  # prompt-based workaround.
  if not isinstance(model, str):
    try:
      from ..models.lite_llm import LiteLlm
    except ImportError:
      LiteLlm = None
    if LiteLlm is not None and isinstance(model, LiteLlm):
      return True

  model_string = model if isinstance(model, str) else model.model

  return (
      get_google_llm_variant() == GoogleLLMVariant.VERTEX_AI
      and is_gemini_eap_or_2_or_above(model_string)
  )
