"""Unit tests for oracle_client.fred (FredService)."""

from __future__ import annotations

import pytest
from pytest_httpx import HTTPXMock


@pytest.mark.asyncio
async def test_get_observations(httpx_mock: HTTPXMock, fred_observations_fixture):
    """FredService.get_observations가 FredProxyResponse를 올바르게 반환한다."""
    from libs.oracle_client.client import OracleClient
    from libs.oracle_client.fred import FredService
    from libs.oracle_client.models import FredProxyResponse

    httpx_mock.add_response(json=fred_observations_fixture)

    async with OracleClient("http://oracle:18001") as client:
        svc = FredService(client)
        result = await svc.get_observations("DGS10")

    assert isinstance(result, FredProxyResponse)
    assert result.series_id == "DGS10"
    assert len(result.observations) == 4
    assert result.observations[0].value == pytest.approx(4.32)


@pytest.mark.asyncio
async def test_get_series_info(httpx_mock: HTTPXMock):
    """FredService.get_series_info가 FredSeriesInfo를 올바르게 반환한다."""
    from libs.oracle_client.client import OracleClient
    from libs.oracle_client.fred import FredService
    from libs.oracle_client.models import FredSeriesInfo

    series_response = {
        "success": True,
        "data": {
            "seriess": [
                {
                    "id": "DGS10",
                    "title": "Market Yield on U.S. Treasury Securities at 10-Year Constant Maturity",
                    "frequency": "Daily",
                    "units": "Percent Per Year",
                }
            ]
        },
    }
    httpx_mock.add_response(json=series_response)

    async with OracleClient("http://oracle:18001") as client:
        svc = FredService(client)
        result = await svc.get_series_info("DGS10")

    assert isinstance(result, FredSeriesInfo)
    assert result.id == "DGS10"
    assert result.frequency == "Daily"
