# 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 jocall3 import Jocall3, AsyncJocall3
from tests.utils import assert_matches_type
from jocall3.types.corporate import (
    CardFreezeResponse,
    CardIssueVirtualResponse,
)

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


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

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_method_list(self, client: Jocall3) -> None:
        card = client.corporate.cards.list()
        assert_matches_type(object, card, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_method_list_with_all_params(self, client: Jocall3) -> None:
        card = client.corporate.cards.list(
            limit=0,
            offset=0,
        )
        assert_matches_type(object, card, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_raw_response_list(self, client: Jocall3) -> None:
        response = client.corporate.cards.with_raw_response.list()

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

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_streaming_response_list(self, client: Jocall3) -> None:
        with client.corporate.cards.with_streaming_response.list() as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            card = response.parse()
            assert_matches_type(object, card, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_method_freeze(self, client: Jocall3) -> None:
        card = client.corporate.cards.freeze(
            "corp_card_xyz987654",
        )
        assert_matches_type(CardFreezeResponse, card, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_raw_response_freeze(self, client: Jocall3) -> None:
        response = client.corporate.cards.with_raw_response.freeze(
            "corp_card_xyz987654",
        )

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

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_streaming_response_freeze(self, client: Jocall3) -> None:
        with client.corporate.cards.with_streaming_response.freeze(
            "corp_card_xyz987654",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            card = response.parse()
            assert_matches_type(CardFreezeResponse, card, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_path_params_freeze(self, client: Jocall3) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `card_id` but received ''"):
            client.corporate.cards.with_raw_response.freeze(
                "",
            )

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_method_issue_virtual(self, client: Jocall3) -> None:
        card = client.corporate.cards.issue_virtual(
            controls={
                "atmWithdrawals": False,
                "contactlessPayments": False,
                "onlineTransactions": True,
                "internationalTransactions": False,
                "monthlyLimit": 1000,
                "dailyLimit": 500,
                "singleTransactionLimit": 200,
                "merchantCategoryRestrictions": ["Advertising"],
                "vendorRestrictions": ["Facebook Ads", "Google Ads"],
            },
        )
        assert_matches_type(CardIssueVirtualResponse, card, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_raw_response_issue_virtual(self, client: Jocall3) -> None:
        response = client.corporate.cards.with_raw_response.issue_virtual(
            controls={
                "atmWithdrawals": False,
                "contactlessPayments": False,
                "onlineTransactions": True,
                "internationalTransactions": False,
                "monthlyLimit": 1000,
                "dailyLimit": 500,
                "singleTransactionLimit": 200,
                "merchantCategoryRestrictions": ["Advertising"],
                "vendorRestrictions": ["Facebook Ads", "Google Ads"],
            },
        )

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

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_streaming_response_issue_virtual(self, client: Jocall3) -> None:
        with client.corporate.cards.with_streaming_response.issue_virtual(
            controls={
                "atmWithdrawals": False,
                "contactlessPayments": False,
                "onlineTransactions": True,
                "internationalTransactions": False,
                "monthlyLimit": 1000,
                "dailyLimit": 500,
                "singleTransactionLimit": 200,
                "merchantCategoryRestrictions": ["Advertising"],
                "vendorRestrictions": ["Facebook Ads", "Google Ads"],
            },
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            card = response.parse()
            assert_matches_type(CardIssueVirtualResponse, card, path=["response"])

        assert cast(Any, response.is_closed) is True


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

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_method_list(self, async_client: AsyncJocall3) -> None:
        card = await async_client.corporate.cards.list()
        assert_matches_type(object, card, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_method_list_with_all_params(self, async_client: AsyncJocall3) -> None:
        card = await async_client.corporate.cards.list(
            limit=0,
            offset=0,
        )
        assert_matches_type(object, card, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_raw_response_list(self, async_client: AsyncJocall3) -> None:
        response = await async_client.corporate.cards.with_raw_response.list()

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

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_streaming_response_list(self, async_client: AsyncJocall3) -> None:
        async with async_client.corporate.cards.with_streaming_response.list() as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            card = await response.parse()
            assert_matches_type(object, card, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_method_freeze(self, async_client: AsyncJocall3) -> None:
        card = await async_client.corporate.cards.freeze(
            "corp_card_xyz987654",
        )
        assert_matches_type(CardFreezeResponse, card, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_raw_response_freeze(self, async_client: AsyncJocall3) -> None:
        response = await async_client.corporate.cards.with_raw_response.freeze(
            "corp_card_xyz987654",
        )

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

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_streaming_response_freeze(self, async_client: AsyncJocall3) -> None:
        async with async_client.corporate.cards.with_streaming_response.freeze(
            "corp_card_xyz987654",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            card = await response.parse()
            assert_matches_type(CardFreezeResponse, card, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_path_params_freeze(self, async_client: AsyncJocall3) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `card_id` but received ''"):
            await async_client.corporate.cards.with_raw_response.freeze(
                "",
            )

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_method_issue_virtual(self, async_client: AsyncJocall3) -> None:
        card = await async_client.corporate.cards.issue_virtual(
            controls={
                "atmWithdrawals": False,
                "contactlessPayments": False,
                "onlineTransactions": True,
                "internationalTransactions": False,
                "monthlyLimit": 1000,
                "dailyLimit": 500,
                "singleTransactionLimit": 200,
                "merchantCategoryRestrictions": ["Advertising"],
                "vendorRestrictions": ["Facebook Ads", "Google Ads"],
            },
        )
        assert_matches_type(CardIssueVirtualResponse, card, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_raw_response_issue_virtual(self, async_client: AsyncJocall3) -> None:
        response = await async_client.corporate.cards.with_raw_response.issue_virtual(
            controls={
                "atmWithdrawals": False,
                "contactlessPayments": False,
                "onlineTransactions": True,
                "internationalTransactions": False,
                "monthlyLimit": 1000,
                "dailyLimit": 500,
                "singleTransactionLimit": 200,
                "merchantCategoryRestrictions": ["Advertising"],
                "vendorRestrictions": ["Facebook Ads", "Google Ads"],
            },
        )

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

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_streaming_response_issue_virtual(self, async_client: AsyncJocall3) -> None:
        async with async_client.corporate.cards.with_streaming_response.issue_virtual(
            controls={
                "atmWithdrawals": False,
                "contactlessPayments": False,
                "onlineTransactions": True,
                "internationalTransactions": False,
                "monthlyLimit": 1000,
                "dailyLimit": 500,
                "singleTransactionLimit": 200,
                "merchantCategoryRestrictions": ["Advertising"],
                "vendorRestrictions": ["Facebook Ads", "Google Ads"],
            },
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            card = await response.parse()
            assert_matches_type(CardIssueVirtualResponse, card, path=["response"])

        assert cast(Any, response.is_closed) is True
