"""Tests for tool behavior with ArcGIS Hub portals."""
from __future__ import annotations

from unittest.mock import AsyncMock, MagicMock

import pytest

from ontario_data.portals import PORTALS


class TestSqlQueryArcGIS:
    @pytest.mark.asyncio
    async def test_returns_not_available(self, make_portal_context):
        from ontario_data.tools.querying import sql_query

        ottawa_client = AsyncMock()
        ctx = make_portal_context(portal_clients={"ottawa": ottawa_client})
        result = await sql_query(sql="SELECT 1", portal="ottawa", ctx=ctx)

        assert "**Not available:**" in result
        assert "download_resource" in result
        ottawa_client.datastore_sql.assert_not_called()


class TestQueryResourceArcGIS:
    @pytest.mark.asyncio
    async def test_returns_not_available(self, make_portal_context):
        from ontario_data.tools.querying import query_resource

        ottawa_client = AsyncMock()
        ctx = make_portal_context(portal_clients={"ottawa": ottawa_client})
        result = await query_resource(resource_id="ottawa:abc123_0", ctx=ctx)

        assert "**Not available:**" in result
        assert "download_resource" in result


class TestPreviewDataArcGIS:
    @pytest.mark.asyncio
    async def test_returns_not_available(self, make_portal_context):
        from ontario_data.tools.querying import preview_data

        ottawa_client = AsyncMock()
        ctx = make_portal_context(portal_clients={"ottawa": ottawa_client})
        result = await preview_data(resource_id="ottawa:abc123_0", ctx=ctx)

        assert "**Not available:**" in result
        assert "download_resource" in result


class TestGetResourceSchemaArcGIS:
    @pytest.mark.asyncio
    async def test_returns_not_available(self, make_portal_context):
        from ontario_data.tools.metadata import get_resource_schema

        ottawa_client = AsyncMock()
        ctx = make_portal_context(portal_clients={"ottawa": ottawa_client})
        result = await get_resource_schema(resource_id="ottawa:abc123_0", ctx=ctx)

        assert "**Not available:**" in result
        assert "download_resource" in result


class TestLoadGeodataArcGIS:
    @pytest.mark.asyncio
    async def test_returns_not_available(self, make_portal_context):
        from ontario_data.tools.geospatial import load_geodata

        ottawa_client = AsyncMock()
        ctx = make_portal_context(portal_clients={"ottawa": ottawa_client})
        result = await load_geodata(resource_id="ottawa:abc123_0", ctx=ctx)

        assert "**Not available:**" in result
        assert "download_resource" in result
