# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import pytest
import pytest_asyncio
from specialwords.aio import SpecialWordsClient
from specialwords import models


@pytest_asyncio.fixture
async def client():
    async with SpecialWordsClient() as client:
        yield client


@pytest.mark.asyncio
async def test_operations(client: SpecialWordsClient, special_words):
    for sw in special_words:
        suffix = "" if sw == "constructor" else "_method"
        await getattr(client.operations, sw + suffix)()


@pytest.mark.asyncio
async def test_parameter(client: SpecialWordsClient, special_words):
    for sw in special_words:
        suffix = "" if sw == "constructor" else "_parameter"
        await getattr(client.parameters, "with_" + sw)(**{sw + suffix: "ok"})
    await client.parameters.with_cancellation_token(cancellation_token="ok")


@pytest.mark.asyncio
async def test_model(client: SpecialWordsClient, special_words):
    for sw in special_words:
        suffix = "" if sw == "constructor" else "Model"
        model = getattr(models, sw.capitalize() + suffix)
        await getattr(client.models, "with_" + sw)(model(name="ok"))


@pytest.mark.asyncio
async def test_model_properties(client: SpecialWordsClient):
    await client.model_properties.same_as_model(models.SameAsModel(same_as_model="ok"))


@pytest.mark.asyncio
async def test_model_properties_dict_methods(client: SpecialWordsClient):
    await client.model_properties.dict_methods(
        body=models.DictMethods(
            keys_property="ok",
            items_property="ok",
            values_property="ok",
            popitem_property="ok",
            clear_property="ok",
            update_property="ok",
            setdefault_property="ok",
            pop_property="ok",
            get_property="ok",
            copy_property="ok",
        )
    )


@pytest.mark.asyncio
async def test_model_properties_with_list(client: SpecialWordsClient):
    await client.model_properties.with_list(models.ModelWithList(list="ok"))


@pytest.mark.asyncio
async def test_extensible_strings(client: SpecialWordsClient):
    for enum_value in models.ExtensibleString:
        assert enum_value == await client.extensible_strings.put_extensible_string_value(body=enum_value)


@pytest.mark.asyncio
async def test_reserved_operation_body_params_with_items(client: SpecialWordsClient):
    await client.reserved_operation_body_params.with_items(items=["item"])
