from unittest.mock import MagicMock

import pytest

from rhodecode.apps.ai_agents.models.gemini import GeminiService
from rhodecode.apps.ai_agents.models.gpt import GPTService


class TestNames:
    @pytest.mark.parametrize(
        "input_, expected_output",
        [
            ("gpt-4-0613", "gpt-4 0613"),
            ("gpt-4", "gpt-4"),
            ("gpt-3.5-turbo", "gpt-3.5 turbo"),
            ("sora-2-pro", "sora-2 pro"),
            ("gpt-audio-mini-2025-10-06", "gpt audio mini 2025-10-06"),
            ("gpt-realtime-mini", "gpt realtime mini"),
            ("gpt-realtime-mini-2025-10-06", "gpt realtime mini 2025-10-06"),
            ("sora-2", "sora-2"),
            ("davinci-002", "davinci 002"),
            ("babbage-002", "babbage 002"),
            ("gpt-3.5-turbo-instruct", "gpt-3.5 turbo instruct"),
            ("gpt-3.5-turbo-instruct-0914", "gpt-3.5 turbo instruct 0914"),
            ("dall-e-3", "dall-e 3"),
            ("gpt-3.5-turbo-1106", "gpt-3.5 turbo 1106"),
            ("gpt-4o-audio-preview", "gpt-4o audio preview"),
            ("gpt-4o-realtime-preview", "gpt-4o realtime preview"),
            ("omni-moderation-latest", "omni moderation latest"),
            ("omni-moderation-2024-09-26", "omni moderation 2024-09-26"),
            ("gpt-4o-realtime-preview-2024-12-17", "gpt-4o realtime preview 2024-12-17"),
            ("gpt-4o-audio-preview-2024-12-17", "gpt-4o audio preview 2024-12-17"),
            ("gpt-4o-mini-realtime-preview-2024-12-17", "gpt-4o mini realtime preview 2024-12-17"),
            ("gpt-4o-mini-audio-preview-2024-12-17", "gpt-4o mini audio preview 2024-12-17"),
            ("o1-2024-12-17", "o1 2024-12-17"),
            ("o1", "o1"),
            ("gpt-4o-mini-realtime-preview", "gpt-4o mini realtime preview"),
            ("gpt-4o-mini-audio-preview", "gpt-4o mini audio preview"),
            ("o3-mini", "o3 mini"),
            ("o3-mini-2025-01-31", "o3 mini 2025-01-31"),
            ("gpt-4o-2024-11-20", "gpt-4o 2024-11-20"),
            ("gpt-4o-search-preview-2025-03-11", "gpt-4o search preview 2025-03-11"),
            ("gpt-4o-search-preview", "gpt-4o search preview"),
            ("gpt-4o-mini-search-preview-2025-03-11", "gpt-4o mini search preview 2025-03-11"),
            ("gpt-4o-mini-search-preview", "gpt-4o mini search preview"),
            ("gpt-4o-transcribe", "gpt-4o transcribe"),
            ("gpt-4o-mini-transcribe", "gpt-4o mini transcribe"),
            ("o1-pro-2025-03-19", "o1 pro 2025-03-19"),
            ("o1-pro", "o1 pro"),
            ("gpt-4o-mini-tts", "gpt-4o mini tts"),
            ("o3-2025-04-16", "o3 2025-04-16"),
            ("gpt-5-pro-2025-10-06", "gpt-5 pro 2025-10-06"),
            ("gpt-5-pro", "gpt-5 pro"),
            ("gpt-audio-mini", "gpt audio mini"),
            ("gpt-3.5-turbo-16k", "gpt-3.5 turbo 16k"),
            ("tts-1", "tts-1"),
            ("whisper-1", "whisper-1"),
            ("text-embedding-ada-002", "text embedding ada 002"),
        ],
    )
    def test_gpt_display_names(self, input_, expected_output):
        service = GPTService(MagicMock())
        display_names = service._to_display_name(input_)
        assert display_names == expected_output

    def test_gemini_api_names(self):
        service = GeminiService(MagicMock())
        input_ = [
            ("models/embedding-gecko-001", "embedding gecko 001"),
            ("models/gemini-2.5-pro-preview-03-25", "gemini-2.5 pro preview 03-25"),
        ]

        cleaned_names = service._remove_models_from_api_name(input_)

        expected_output = [
            ("embedding-gecko-001", "embedding gecko 001"),
            ("gemini-2.5-pro-preview-03-25", "gemini-2.5 pro preview 03-25"),
        ]
        assert cleaned_names == expected_output
