# 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 import NotiflowRunResponse

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


class TestNotiflows:
    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_run(self, client: Notiflows) -> None:
        notiflow = client.notiflows.run(
            notiflow_handle="welcome-email",
        )
        assert_matches_type(NotiflowRunResponse, notiflow, path=["response"])

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_method_run_with_all_params(self, client: Notiflows) -> None:
        notiflow = client.notiflows.run(
            notiflow_handle="welcome-email",
            actor={
                "external_id": "admin_001",
                "avatar": "https://example.com",
                "custom_fields": {},
                "email": "admin@example.com",
                "first_name": "Admin",
                "last_name": "User",
                "locale": "en-US",
                "phone": "+15551234567",
                "timezone": "America/New_York",
            },
            data={
                "order_id": "ORD-12345",
                "total": "$99.99",
            },
            recipients=[
                {
                    "external_id": "user_12345",
                    "avatar": "https://example.com",
                    "custom_fields": {},
                    "email": "jane@example.com",
                    "first_name": "Jane",
                    "last_name": "Doe",
                    "locale": "en-US",
                    "phone": "+15551234567",
                    "timezone": "America/New_York",
                }
            ],
            topic="order-updates",
        )
        assert_matches_type(NotiflowRunResponse, notiflow, path=["response"])

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_raw_response_run(self, client: Notiflows) -> None:
        response = client.notiflows.with_raw_response.run(
            notiflow_handle="welcome-email",
        )

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

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    def test_streaming_response_run(self, client: Notiflows) -> None:
        with client.notiflows.with_streaming_response.run(
            notiflow_handle="welcome-email",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            notiflow = response.parse()
            assert_matches_type(NotiflowRunResponse, notiflow, 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_run(self, client: Notiflows) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `notiflow_handle` but received ''"):
            client.notiflows.with_raw_response.run(
                notiflow_handle="",
            )


class TestAsyncNotiflows:
    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_run(self, async_client: AsyncNotiflows) -> None:
        notiflow = await async_client.notiflows.run(
            notiflow_handle="welcome-email",
        )
        assert_matches_type(NotiflowRunResponse, notiflow, path=["response"])

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_method_run_with_all_params(self, async_client: AsyncNotiflows) -> None:
        notiflow = await async_client.notiflows.run(
            notiflow_handle="welcome-email",
            actor={
                "external_id": "admin_001",
                "avatar": "https://example.com",
                "custom_fields": {},
                "email": "admin@example.com",
                "first_name": "Admin",
                "last_name": "User",
                "locale": "en-US",
                "phone": "+15551234567",
                "timezone": "America/New_York",
            },
            data={
                "order_id": "ORD-12345",
                "total": "$99.99",
            },
            recipients=[
                {
                    "external_id": "user_12345",
                    "avatar": "https://example.com",
                    "custom_fields": {},
                    "email": "jane@example.com",
                    "first_name": "Jane",
                    "last_name": "Doe",
                    "locale": "en-US",
                    "phone": "+15551234567",
                    "timezone": "America/New_York",
                }
            ],
            topic="order-updates",
        )
        assert_matches_type(NotiflowRunResponse, notiflow, path=["response"])

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_raw_response_run(self, async_client: AsyncNotiflows) -> None:
        response = await async_client.notiflows.with_raw_response.run(
            notiflow_handle="welcome-email",
        )

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

    @pytest.mark.skip(reason="Prism doesn't support callbacks yet")
    @parametrize
    async def test_streaming_response_run(self, async_client: AsyncNotiflows) -> None:
        async with async_client.notiflows.with_streaming_response.run(
            notiflow_handle="welcome-email",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            notiflow = await response.parse()
            assert_matches_type(NotiflowRunResponse, notiflow, 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_run(self, async_client: AsyncNotiflows) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `notiflow_handle` but received ''"):
            await async_client.notiflows.with_raw_response.run(
                notiflow_handle="",
            )
