# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

import os
from typing import Any, cast

import pytest

from millionways import Millionways, AsyncMillionways
from tests.utils import assert_matches_type
from millionways.types import (
    ChatGenerateResponseResponse,
    ChatGenerateResponseForUserResponse,
)

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")


class TestChat:
    parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])

    @pytest.mark.skip()
    @parametrize
    def test_method_generate_response(self, client: Millionways) -> None:
        chat = client.chat.generate_response(
            api_key="apiKey",
        )
        assert_matches_type(ChatGenerateResponseResponse, chat, path=["response"])

    @pytest.mark.skip()
    @parametrize
    def test_method_generate_response_with_all_params(self, client: Millionways) -> None:
        chat = client.chat.generate_response(
            api_key="apiKey",
            language="en",
            messages=[
                {
                    "role": "user",
                    "content": "Hello",
                },
                {
                    "role": "assistant",
                    "content": "Hi, how are you?",
                },
            ],
        )
        assert_matches_type(ChatGenerateResponseResponse, chat, path=["response"])

    @pytest.mark.skip()
    @parametrize
    def test_raw_response_generate_response(self, client: Millionways) -> None:
        response = client.chat.with_raw_response.generate_response(
            api_key="apiKey",
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        chat = response.parse()
        assert_matches_type(ChatGenerateResponseResponse, chat, path=["response"])

    @pytest.mark.skip()
    @parametrize
    def test_streaming_response_generate_response(self, client: Millionways) -> None:
        with client.chat.with_streaming_response.generate_response(
            api_key="apiKey",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            chat = response.parse()
            assert_matches_type(ChatGenerateResponseResponse, chat, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip()
    @parametrize
    def test_method_generate_response_for_user(self, client: Millionways) -> None:
        chat = client.chat.generate_response_for_user(
            user_id="userId",
            api_key="apiKey",
        )
        assert_matches_type(ChatGenerateResponseForUserResponse, chat, path=["response"])

    @pytest.mark.skip()
    @parametrize
    def test_method_generate_response_for_user_with_all_params(self, client: Millionways) -> None:
        chat = client.chat.generate_response_for_user(
            user_id="userId",
            api_key="apiKey",
            language="en",
            messages=[
                {
                    "role": "user",
                    "content": "Hello",
                },
                {
                    "role": "assistant",
                    "content": "Hi, how are you?",
                },
            ],
        )
        assert_matches_type(ChatGenerateResponseForUserResponse, chat, path=["response"])

    @pytest.mark.skip()
    @parametrize
    def test_raw_response_generate_response_for_user(self, client: Millionways) -> None:
        response = client.chat.with_raw_response.generate_response_for_user(
            user_id="userId",
            api_key="apiKey",
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        chat = response.parse()
        assert_matches_type(ChatGenerateResponseForUserResponse, chat, path=["response"])

    @pytest.mark.skip()
    @parametrize
    def test_streaming_response_generate_response_for_user(self, client: Millionways) -> None:
        with client.chat.with_streaming_response.generate_response_for_user(
            user_id="userId",
            api_key="apiKey",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            chat = response.parse()
            assert_matches_type(ChatGenerateResponseForUserResponse, chat, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip()
    @parametrize
    def test_path_params_generate_response_for_user(self, client: Millionways) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_id` but received ''"):
            client.chat.with_raw_response.generate_response_for_user(
                user_id="",
                api_key="apiKey",
            )


class TestAsyncChat:
    parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])

    @pytest.mark.skip()
    @parametrize
    async def test_method_generate_response(self, async_client: AsyncMillionways) -> None:
        chat = await async_client.chat.generate_response(
            api_key="apiKey",
        )
        assert_matches_type(ChatGenerateResponseResponse, chat, path=["response"])

    @pytest.mark.skip()
    @parametrize
    async def test_method_generate_response_with_all_params(self, async_client: AsyncMillionways) -> None:
        chat = await async_client.chat.generate_response(
            api_key="apiKey",
            language="en",
            messages=[
                {
                    "role": "user",
                    "content": "Hello",
                },
                {
                    "role": "assistant",
                    "content": "Hi, how are you?",
                },
            ],
        )
        assert_matches_type(ChatGenerateResponseResponse, chat, path=["response"])

    @pytest.mark.skip()
    @parametrize
    async def test_raw_response_generate_response(self, async_client: AsyncMillionways) -> None:
        response = await async_client.chat.with_raw_response.generate_response(
            api_key="apiKey",
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        chat = await response.parse()
        assert_matches_type(ChatGenerateResponseResponse, chat, path=["response"])

    @pytest.mark.skip()
    @parametrize
    async def test_streaming_response_generate_response(self, async_client: AsyncMillionways) -> None:
        async with async_client.chat.with_streaming_response.generate_response(
            api_key="apiKey",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            chat = await response.parse()
            assert_matches_type(ChatGenerateResponseResponse, chat, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip()
    @parametrize
    async def test_method_generate_response_for_user(self, async_client: AsyncMillionways) -> None:
        chat = await async_client.chat.generate_response_for_user(
            user_id="userId",
            api_key="apiKey",
        )
        assert_matches_type(ChatGenerateResponseForUserResponse, chat, path=["response"])

    @pytest.mark.skip()
    @parametrize
    async def test_method_generate_response_for_user_with_all_params(self, async_client: AsyncMillionways) -> None:
        chat = await async_client.chat.generate_response_for_user(
            user_id="userId",
            api_key="apiKey",
            language="en",
            messages=[
                {
                    "role": "user",
                    "content": "Hello",
                },
                {
                    "role": "assistant",
                    "content": "Hi, how are you?",
                },
            ],
        )
        assert_matches_type(ChatGenerateResponseForUserResponse, chat, path=["response"])

    @pytest.mark.skip()
    @parametrize
    async def test_raw_response_generate_response_for_user(self, async_client: AsyncMillionways) -> None:
        response = await async_client.chat.with_raw_response.generate_response_for_user(
            user_id="userId",
            api_key="apiKey",
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        chat = await response.parse()
        assert_matches_type(ChatGenerateResponseForUserResponse, chat, path=["response"])

    @pytest.mark.skip()
    @parametrize
    async def test_streaming_response_generate_response_for_user(self, async_client: AsyncMillionways) -> None:
        async with async_client.chat.with_streaming_response.generate_response_for_user(
            user_id="userId",
            api_key="apiKey",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            chat = await response.parse()
            assert_matches_type(ChatGenerateResponseForUserResponse, chat, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip()
    @parametrize
    async def test_path_params_generate_response_for_user(self, async_client: AsyncMillionways) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_id` but received ''"):
            await async_client.chat.with_raw_response.generate_response_for_user(
                user_id="",
                api_key="apiKey",
            )
