"""Conversion utilities between API payloads and model objects."""

from __future__ import annotations

from typing import Any, Dict, List

from sd_api.models.quote import Quote
from sd_api.models.kline import KlineBar


def dict_to_quote(data: Dict[str, Any]) -> Quote:
    """Convert a raw API dict to a Quote model.

    Alias for Quote.from_api().
    """
    return Quote.from_api(data)


def list_to_kline_bar(lst: List) -> KlineBar:
    """Convert a [ts, open, high, low, close] list to a KlineBar.

    Alias for KlineBar.from_list().
    """
    return KlineBar.from_list(lst)


def quote_to_row(quote: Quote) -> Dict[str, Any]:
    """Flatten a Quote into a dict suitable for DataFrame / CSV storage."""
    return quote.to_dict()


def bar_to_row(bar: KlineBar) -> Dict[str, Any]:
    """Flatten a KlineBar into a dict."""
    return bar.to_dict()
