"""Company info Oracle service methods."""

from __future__ import annotations

from libs.oracle_client.client import OracleClient
from libs.oracle_client.models import CompanyInfo


class CompanyService:
    def __init__(self, client: OracleClient) -> None:
        self._client = client

    async def get_company(self, symbol: str) -> CompanyInfo:
        """Fetch company info via GET /api/v1/financial/data/{symbol}.

        Uses the financial/data endpoint because /api/v1/company/{symbol}
        does not exist in the current Stock Oracle API.
        """
        data = await self._client.get(
            f"/api/v1/financial/data/{symbol}", params={"period": "1y"}
        )
        company = data.get("company", {})
        return CompanyInfo(
            ticker=company.get("ticker", symbol),
            name=company.get("name"),
            cik=company.get("cik"),
            exchange=company.get("exchange"),
            sector=company.get("sector"),
            industry=company.get("industry"),
            country=company.get("country"),
            market_cap=company.get("market_cap"),
        )
