"""Shared option-data types used across multiple algorithms.

Kept in one place so that :mod:`liquidity_gate`, :mod:`combo_builder`,
:mod:`greeks_aggregator` and :mod:`exit_decision` agree on the same
record format. The orchestrator is responsible for assembling
:class:`OptionQuote` instances from the raw MCP responses.
"""

from __future__ import annotations

from datetime import datetime
from decimal import Decimal
from typing import Literal

from pydantic import BaseModel, ConfigDict

__all__ = ["OptionLeg", "OptionQuote", "OrderSide", "PutOrCall"]


PutOrCall = Literal["P", "C"]
OrderSide = Literal["BUY", "SELL"]


class OptionQuote(BaseModel):
    """Full market + greeks snapshot for a single option instrument.

    Used by combo selection (greeks + strike + expiry) and by the
    liquidity gate (bid/ask/depth). Time information is in UTC.
    """

    model_config = ConfigDict(frozen=True, extra="forbid")

    instrument: str
    strike: Decimal
    expiry: datetime
    option_type: PutOrCall

    bid: Decimal
    ask: Decimal
    mid: Decimal

    delta: Decimal
    gamma: Decimal
    theta: Decimal
    vega: Decimal

    open_interest: int
    volume_24h: int
    book_depth_top3: int


class OptionLeg(BaseModel):
    """Single leg of an option spread, ready for execution.

    The signed greeks are stored leg-level (not net): aggregation is done
    by :func:`cerbero_bite.core.greeks_aggregator.aggregate`.
    """

    model_config = ConfigDict(frozen=True, extra="forbid")

    instrument: str
    side: OrderSide
    strike: Decimal
    expiry: datetime
    type: PutOrCall
    size: int

    mid_price_eth: Decimal
    delta: Decimal
    gamma: Decimal
    theta: Decimal
    vega: Decimal
