"""Products (instrument spec) endpoint."""

from __future__ import annotations

from typing import Dict

from sd_api.client.base import BaseClient
from sd_api.models.product import ProductSpec


class ProductsMixin:
    """Endpoints under /api/products."""

    def __init__(self, base: BaseClient) -> None:
        self._base = base

    def list(self) -> Dict[str, Dict[str, str | int]]:
        """GET /api/products — full product spec table.

        Returns a dict keyed by symbol name.
        """
        data = self._base.get("/api/products")
        return data  # raw dict of {symbol: {size, lev, currency, type}}

    def get(self, symbol: str) -> ProductSpec:
        """GET /api/products and return a ProductSpec for the given symbol."""
        all_specs = self.list()
        symbol = symbol.upper().strip()
        raw = all_specs.get(symbol, {})
        return ProductSpec.from_dict(symbol, raw)
