import httpx
import pytest
import respx

from anyfast import AnyFast


@pytest.fixture
def client():
    return AnyFast(api_key="test-key")


class TestAsset:
    @respx.mock
    def test_create_group(self, client):
        route = respx.post("https://www.anyfast.ai/volc/asset/CreateAssetGroup").mock(
            return_value=httpx.Response(200, json={"Id": "group-001"})
        )

        result = client.asset.create_group(Name="my-group")

        assert route.called
        assert result["Id"] == "group-001"

    @respx.mock
    def test_list_groups(self, client):
        route = respx.post("https://www.anyfast.ai/volc/asset/ListAssetGroups").mock(
            return_value=httpx.Response(200, json={
                "Items": [{"Id": "group-001", "Name": "my-group"}],
                "PageNumber": 1,
                "PageSize": 10,
                "TotalCount": 1,
            })
        )

        result = client.asset.list_groups()

        assert route.called
        assert len(result["Items"]) == 1

    @respx.mock
    def test_create_asset(self, client):
        route = respx.post("https://www.anyfast.ai/volc/asset/CreateAsset").mock(
            return_value=httpx.Response(200, json={"Id": "asset-001"})
        )

        result = client.asset.create_asset(
            GroupId="group-001",
            Name="test-image",
            AssetType="Image",
            URL="https://example.com/image.png",
        )

        assert route.called
        assert result["Id"] == "asset-001"

    @respx.mock
    def test_list_assets(self, client):
        route = respx.post("https://www.anyfast.ai/volc/asset/ListAssets").mock(
            return_value=httpx.Response(200, json={
                "Items": [
                    {
                        "Id": "asset-001",
                        "Name": "test-image",
                        "URL": "https://cdn.example.com/image.png",
                        "AssetType": "Image",
                        "GroupId": "group-001",
                        "Status": "Active",
                    }
                ],
                "PageNumber": 1,
                "PageSize": 10,
                "TotalCount": 1,
            })
        )

        result = client.asset.list_assets(Filter={"GroupIds": ["group-001"]})

        assert route.called
        assert result["Items"][0]["Status"] == "Active"
