"""
Type definitions for Polymarket APIs.

This module contains all the Pydantic models and type definitions used across
the Polymarket APIs.
"""

from __future__ import annotations

from importlib import import_module
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
    from .clob_types import (
        ApiCreds,
        AssetType,
        BidAsk,
        BookParams,
        ClobMarket,
        ContractConfig,
        CreateOrderOptions,
        DailyEarnedReward,
        MarketOrderArgs,
        MarketRewards,
        Midpoint,
        OpenOrder,
        OrderArgs,
        OrderBookSummary,
        OrderCancelResponse,
        OrderPostResponse,
        OrderType,
        PaginatedResponse,
        PartialCreateOrderOptions,
        PolygonTrade,
        PostOrdersArgs,
        Price,
        PriceHistory,
        RewardMarket,
        Spread,
        TickSize,
        Token,
        TokenBidAsk,
        TokenBidAskDict,
        TokenValue,
        TokenValueDict,
    )
    from .common import (
        EmptyString,
        EthAddress,
        FlexibleDatetime,
        Keccak256,
        TimeseriesPoint,
    )
    from .data_types import (
        Activity,
        ActivityType,
        Holder,
        HolderResponse,
        Position,
        Trade,
        User,
        UserMetric,
        UserRank,
        ValueResponse,
    )
    from .gamma_types import ClobReward, Event, GammaMarket, Pagination, Series, Tag
    from .websockets_types import (
        ActivityOrderMatchEvent,
        ActivityTradeEvent,
        AssetPriceSubscribeEvent,
        AssetPriceUpdateEvent,
        BestBidAskEvent,
        CommentEvent,
        ErrorEvent,
        LastTradePriceEvent,
        LiveDataEvents,
        MarketEvents,
        MarketResolvedEvent,
        NewMarketEvent,
        OrderBookSummaryEvent,
        OrderEvent,
        PriceChangeEvent,
        QuoteEvent,
        ReactionEvent,
        RequestEvent,
        SportsGameUpdate,
        TickSizeChangeEvent,
        TradeEvent,
        UserEvents,
    )

__all__ = [
    "Activity",
    "ActivityOrderMatchEvent",
    "ActivityTradeEvent",
    "ActivityType",
    "ApiCreds",
    "AssetPriceSubscribeEvent",
    "AssetPriceUpdateEvent",
    "AssetType",
    "BestBidAskEvent",
    "BidAsk",
    "BookParams",
    "ClobMarket",
    "ClobReward",
    "CommentEvent",
    "ContractConfig",
    "CreateOrderOptions",
    "DailyEarnedReward",
    "EmptyString",
    "ErrorEvent",
    "EthAddress",
    "Event",
    "FlexibleDatetime",
    "GammaMarket",
    "Holder",
    "HolderResponse",
    "Keccak256",
    "LastTradePriceEvent",
    "LiveDataEvents",
    "MarketEvents",
    "MarketOrderArgs",
    "MarketResolvedEvent",
    "MarketRewards",
    "Midpoint",
    "NewMarketEvent",
    "OpenOrder",
    "OrderArgs",
    "OrderBookSummary",
    "OrderBookSummaryEvent",
    "OrderCancelResponse",
    "OrderEvent",
    "OrderPostResponse",
    "OrderType",
    "PaginatedResponse",
    "Pagination",
    "PartialCreateOrderOptions",
    "PolygonTrade",
    "Position",
    "PostOrdersArgs",
    "Price",
    "PriceChangeEvent",
    "PriceHistory",
    "QuoteEvent",
    "ReactionEvent",
    "RequestEvent",
    "RewardMarket",
    "Series",
    "SportsGameUpdate",
    "Spread",
    "Tag",
    "TickSize",
    "TickSizeChangeEvent",
    "TimeseriesPoint",
    "Token",
    "TokenBidAsk",
    "TokenBidAskDict",
    "TokenValue",
    "TokenValueDict",
    "Trade",
    "TradeEvent",
    "User",
    "UserEvents",
    "UserMetric",
    "UserRank",
    "ValueResponse",
]

_EXPORT_MAP = {
    "Activity": ".data_types",
    "ActivityOrderMatchEvent": ".websockets_types",
    "ActivityTradeEvent": ".websockets_types",
    "ActivityType": ".data_types",
    "ApiCreds": ".clob_types",
    "AssetPriceSubscribeEvent": ".websockets_types",
    "AssetPriceUpdateEvent": ".websockets_types",
    "AssetType": ".clob_types",
    "BestBidAskEvent": ".websockets_types",
    "BidAsk": ".clob_types",
    "BookParams": ".clob_types",
    "ClobMarket": ".clob_types",
    "ClobReward": ".gamma_types",
    "CommentEvent": ".websockets_types",
    "ContractConfig": ".clob_types",
    "CreateOrderOptions": ".clob_types",
    "DailyEarnedReward": ".clob_types",
    "EmptyString": ".common",
    "ErrorEvent": ".websockets_types",
    "EthAddress": ".common",
    "Event": ".gamma_types",
    "FlexibleDatetime": ".common",
    "GammaMarket": ".gamma_types",
    "Holder": ".data_types",
    "HolderResponse": ".data_types",
    "Keccak256": ".common",
    "LastTradePriceEvent": ".websockets_types",
    "LiveDataEvents": ".websockets_types",
    "MarketEvents": ".websockets_types",
    "MarketOrderArgs": ".clob_types",
    "MarketResolvedEvent": ".websockets_types",
    "MarketRewards": ".clob_types",
    "Midpoint": ".clob_types",
    "NewMarketEvent": ".websockets_types",
    "OpenOrder": ".clob_types",
    "OrderArgs": ".clob_types",
    "OrderBookSummary": ".clob_types",
    "OrderBookSummaryEvent": ".websockets_types",
    "OrderCancelResponse": ".clob_types",
    "OrderEvent": ".websockets_types",
    "OrderPostResponse": ".clob_types",
    "OrderType": ".clob_types",
    "PaginatedResponse": ".clob_types",
    "Pagination": ".gamma_types",
    "PartialCreateOrderOptions": ".clob_types",
    "PolygonTrade": ".clob_types",
    "Position": ".data_types",
    "PostOrdersArgs": ".clob_types",
    "Price": ".clob_types",
    "PriceChangeEvent": ".websockets_types",
    "PriceHistory": ".clob_types",
    "QuoteEvent": ".websockets_types",
    "ReactionEvent": ".websockets_types",
    "RequestEvent": ".websockets_types",
    "RewardMarket": ".clob_types",
    "Series": ".gamma_types",
    "SportsGameUpdate": ".websockets_types",
    "Spread": ".clob_types",
    "Tag": ".gamma_types",
    "TickSize": ".clob_types",
    "TickSizeChangeEvent": ".websockets_types",
    "TimeseriesPoint": ".common",
    "Token": ".clob_types",
    "TokenBidAsk": ".clob_types",
    "TokenBidAskDict": ".clob_types",
    "TokenValue": ".clob_types",
    "TokenValueDict": ".clob_types",
    "Trade": ".data_types",
    "TradeEvent": ".websockets_types",
    "User": ".data_types",
    "UserEvents": ".websockets_types",
    "UserMetric": ".data_types",
    "UserRank": ".data_types",
    "ValueResponse": ".data_types",
}


def __getattr__(name: str) -> Any:
    module_name = _EXPORT_MAP.get(name)
    if module_name is None:
        msg = f"module {__name__!r} has no attribute {name!r}"
        raise AttributeError(msg)

    module = import_module(module_name, __name__)
    value = getattr(module, name)
    globals()[name] = value
    return value
