# 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 notiflows import Notiflows, AsyncNotiflows
from tests.utils import assert_matches_type
from notiflows.types.users import ChannelSettings

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


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

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_method_retrieve(self, client: Notiflows) -> None:
        channel_setting = client.users.channel_settings.retrieve(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
        )
        assert_matches_type(ChannelSettings, channel_setting, path=["response"])

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_raw_response_retrieve(self, client: Notiflows) -> None:
        response = client.users.channel_settings.with_raw_response.retrieve(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
        )

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

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_streaming_response_retrieve(self, client: Notiflows) -> None:
        with client.users.channel_settings.with_streaming_response.retrieve(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            channel_setting = response.parse()
            assert_matches_type(ChannelSettings, channel_setting, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_path_params_retrieve(self, client: Notiflows) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_external_id` but received ''"):
            client.users.channel_settings.with_raw_response.retrieve(
                channel_id="01HQXYZ123456789ABCDEFGHIJ",
                user_external_id="",
            )

        with pytest.raises(ValueError, match=r"Expected a non-empty value for `channel_id` but received ''"):
            client.users.channel_settings.with_raw_response.retrieve(
                channel_id="",
                user_external_id="user_12345",
            )

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_method_update(self, client: Notiflows) -> None:
        channel_setting = client.users.channel_settings.update(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
            settings={"device_tokens": ["ExampleTokenABCDEF123456789..."]},
        )
        assert_matches_type(ChannelSettings, channel_setting, path=["response"])

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_method_update_with_all_params(self, client: Notiflows) -> None:
        channel_setting = client.users.channel_settings.update(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
            settings={"device_tokens": ["ExampleTokenABCDEF123456789..."]},
        )
        assert_matches_type(ChannelSettings, channel_setting, path=["response"])

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_raw_response_update(self, client: Notiflows) -> None:
        response = client.users.channel_settings.with_raw_response.update(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
            settings={"device_tokens": ["ExampleTokenABCDEF123456789..."]},
        )

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

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_streaming_response_update(self, client: Notiflows) -> None:
        with client.users.channel_settings.with_streaming_response.update(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
            settings={"device_tokens": ["ExampleTokenABCDEF123456789..."]},
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            channel_setting = response.parse()
            assert_matches_type(ChannelSettings, channel_setting, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_path_params_update(self, client: Notiflows) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_external_id` but received ''"):
            client.users.channel_settings.with_raw_response.update(
                channel_id="01HQXYZ123456789ABCDEFGHIJ",
                user_external_id="",
                settings={"device_tokens": ["ExampleTokenABCDEF123456789..."]},
            )

        with pytest.raises(ValueError, match=r"Expected a non-empty value for `channel_id` but received ''"):
            client.users.channel_settings.with_raw_response.update(
                channel_id="",
                user_external_id="user_12345",
                settings={"device_tokens": ["ExampleTokenABCDEF123456789..."]},
            )

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_method_delete(self, client: Notiflows) -> None:
        channel_setting = client.users.channel_settings.delete(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
        )
        assert channel_setting is None

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_raw_response_delete(self, client: Notiflows) -> None:
        response = client.users.channel_settings.with_raw_response.delete(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        channel_setting = response.parse()
        assert channel_setting is None

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_streaming_response_delete(self, client: Notiflows) -> None:
        with client.users.channel_settings.with_streaming_response.delete(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            channel_setting = response.parse()
            assert channel_setting is None

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_path_params_delete(self, client: Notiflows) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_external_id` but received ''"):
            client.users.channel_settings.with_raw_response.delete(
                channel_id="01HQXYZ123456789ABCDEFGHIJ",
                user_external_id="",
            )

        with pytest.raises(ValueError, match=r"Expected a non-empty value for `channel_id` but received ''"):
            client.users.channel_settings.with_raw_response.delete(
                channel_id="",
                user_external_id="user_12345",
            )


class TestAsyncChannelSettings:
    parametrize = pytest.mark.parametrize(
        "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
    )

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_method_retrieve(self, async_client: AsyncNotiflows) -> None:
        channel_setting = await async_client.users.channel_settings.retrieve(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
        )
        assert_matches_type(ChannelSettings, channel_setting, path=["response"])

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_raw_response_retrieve(self, async_client: AsyncNotiflows) -> None:
        response = await async_client.users.channel_settings.with_raw_response.retrieve(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
        )

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

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_streaming_response_retrieve(self, async_client: AsyncNotiflows) -> None:
        async with async_client.users.channel_settings.with_streaming_response.retrieve(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            channel_setting = await response.parse()
            assert_matches_type(ChannelSettings, channel_setting, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_path_params_retrieve(self, async_client: AsyncNotiflows) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_external_id` but received ''"):
            await async_client.users.channel_settings.with_raw_response.retrieve(
                channel_id="01HQXYZ123456789ABCDEFGHIJ",
                user_external_id="",
            )

        with pytest.raises(ValueError, match=r"Expected a non-empty value for `channel_id` but received ''"):
            await async_client.users.channel_settings.with_raw_response.retrieve(
                channel_id="",
                user_external_id="user_12345",
            )

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_method_update(self, async_client: AsyncNotiflows) -> None:
        channel_setting = await async_client.users.channel_settings.update(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
            settings={"device_tokens": ["ExampleTokenABCDEF123456789..."]},
        )
        assert_matches_type(ChannelSettings, channel_setting, path=["response"])

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_method_update_with_all_params(self, async_client: AsyncNotiflows) -> None:
        channel_setting = await async_client.users.channel_settings.update(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
            settings={"device_tokens": ["ExampleTokenABCDEF123456789..."]},
        )
        assert_matches_type(ChannelSettings, channel_setting, path=["response"])

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_raw_response_update(self, async_client: AsyncNotiflows) -> None:
        response = await async_client.users.channel_settings.with_raw_response.update(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
            settings={"device_tokens": ["ExampleTokenABCDEF123456789..."]},
        )

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

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_streaming_response_update(self, async_client: AsyncNotiflows) -> None:
        async with async_client.users.channel_settings.with_streaming_response.update(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
            settings={"device_tokens": ["ExampleTokenABCDEF123456789..."]},
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            channel_setting = await response.parse()
            assert_matches_type(ChannelSettings, channel_setting, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_path_params_update(self, async_client: AsyncNotiflows) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_external_id` but received ''"):
            await async_client.users.channel_settings.with_raw_response.update(
                channel_id="01HQXYZ123456789ABCDEFGHIJ",
                user_external_id="",
                settings={"device_tokens": ["ExampleTokenABCDEF123456789..."]},
            )

        with pytest.raises(ValueError, match=r"Expected a non-empty value for `channel_id` but received ''"):
            await async_client.users.channel_settings.with_raw_response.update(
                channel_id="",
                user_external_id="user_12345",
                settings={"device_tokens": ["ExampleTokenABCDEF123456789..."]},
            )

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_method_delete(self, async_client: AsyncNotiflows) -> None:
        channel_setting = await async_client.users.channel_settings.delete(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
        )
        assert channel_setting is None

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_raw_response_delete(self, async_client: AsyncNotiflows) -> None:
        response = await async_client.users.channel_settings.with_raw_response.delete(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        channel_setting = await response.parse()
        assert channel_setting is None

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_streaming_response_delete(self, async_client: AsyncNotiflows) -> None:
        async with async_client.users.channel_settings.with_streaming_response.delete(
            channel_id="01HQXYZ123456789ABCDEFGHIJ",
            user_external_id="user_12345",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            channel_setting = await response.parse()
            assert channel_setting is None

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_path_params_delete(self, async_client: AsyncNotiflows) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_external_id` but received ''"):
            await async_client.users.channel_settings.with_raw_response.delete(
                channel_id="01HQXYZ123456789ABCDEFGHIJ",
                user_external_id="",
            )

        with pytest.raises(ValueError, match=r"Expected a non-empty value for `channel_id` but received ''"):
            await async_client.users.channel_settings.with_raw_response.delete(
                channel_id="",
                user_external_id="user_12345",
            )
