"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .bidaskprice import BidAskPrice, BidAskPriceTypedDict
from ascend_sdk import utils
from ascend_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from ascend_sdk.utils import validate_open_enum
from datetime import datetime
from enum import Enum
from pydantic import model_serializer
from pydantic.functional_validators import PlainValidator
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class AskMinimumQuantityTypedDict(TypedDict):
    r"""The best ask minimum quantity. This will be absent if no ask information is available"""

    value: NotRequired[str]
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class AskMinimumQuantity(BaseModel):
    r"""The best ask minimum quantity. This will be absent if no ask information is available"""

    value: Optional[str] = None
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class AskQuantityTypedDict(TypedDict):
    r"""The best ask quantity. This will be absent if no ask information is available"""

    value: NotRequired[str]
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class AskQuantity(BaseModel):
    r"""The best ask quantity. This will be absent if no ask information is available"""

    value: Optional[str] = None
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class RetrieveQuoteResponseAssetType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The type of asset referenced by the security identifier"""

    ASSET_TYPE_UNSPECIFIED = "ASSET_TYPE_UNSPECIFIED"
    EQUITY = "EQUITY"
    FIXED_INCOME = "FIXED_INCOME"
    MUTUAL_FUND = "MUTUAL_FUND"


class BidMinimumQuantityTypedDict(TypedDict):
    r"""The best bid minimum quantity. This will be absent if no bid information is available"""

    value: NotRequired[str]
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class BidMinimumQuantity(BaseModel):
    r"""The best bid minimum quantity. This will be absent if no bid information is available"""

    value: Optional[str] = None
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class BidQuantityTypedDict(TypedDict):
    r"""The best bid quantity. This will be absent if no bid information is available"""

    value: NotRequired[str]
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class BidQuantity(BaseModel):
    r"""The best bid quantity. This will be absent if no bid information is available"""

    value: Optional[str] = None
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class RetrieveQuoteResponseBrokerCapacity(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Capacity used in determining bid and ask prices. Defaults to \"AGENCY\" if no value specified."""

    BROKER_CAPACITY_UNSPECIFIED = "BROKER_CAPACITY_UNSPECIFIED"
    AGENCY = "AGENCY"
    PRINCIPAL = "PRINCIPAL"


class RetrieveQuoteResponseIdentifierType(str, Enum):
    r"""The identifier type of the asset for which the best bid and offer is returned. This will be the same value as what was sent on the request."""

    ASSET_ID = "ASSET_ID"
    CUSIP = "CUSIP"
    ISIN = "ISIN"


class MinimumQuantityTypedDict(TypedDict):
    r"""The minimum quantity specified in the request (if any). For Fixed Income: Expressed in the par (face-value) amount and may not exceed two decimal places for USD-based currencies."""

    value: NotRequired[str]
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class MinimumQuantity(BaseModel):
    r"""The minimum quantity specified in the request (if any). For Fixed Income: Expressed in the par (face-value) amount and may not exceed two decimal places for USD-based currencies."""

    value: Optional[str] = None
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class RetrieveQuoteResponseTypedDict(TypedDict):
    r"""The current best bid and offer for a specified security"""

    account_id: NotRequired[str]
    r"""The account id used in calculating order costs"""
    ask_minimum_quantity: NotRequired[Nullable[AskMinimumQuantityTypedDict]]
    r"""The best ask minimum quantity. This will be absent if no ask information is available"""
    ask_prices: NotRequired[List[BidAskPriceTypedDict]]
    r"""The price information of the best ask matching the request criteria. If no ask information is available at all, this will be empty. If yield information is not available, then this will only contain a PERCENTAGE_OF_PAR-typed price."""
    ask_quantity: NotRequired[Nullable[AskQuantityTypedDict]]
    r"""The best ask quantity. This will be absent if no ask information is available"""
    asset_id: NotRequired[str]
    r"""Apex Asset ID for this asset."""
    asset_type: NotRequired[RetrieveQuoteResponseAssetType]
    r"""The type of asset referenced by the security identifier"""
    bid_minimum_quantity: NotRequired[Nullable[BidMinimumQuantityTypedDict]]
    r"""The best bid minimum quantity. This will be absent if no bid information is available"""
    bid_prices: NotRequired[List[BidAskPriceTypedDict]]
    r"""The price information of the best bid matching the request criteria. If no bid information is available at all, this will be empty. If yield information is not available, then this will only contain a PERCENTAGE_OF_PAR-typed price."""
    bid_quantity: NotRequired[Nullable[BidQuantityTypedDict]]
    r"""The best bid quantity. This will be absent if no bid information is available"""
    broker_capacity: NotRequired[RetrieveQuoteResponseBrokerCapacity]
    r"""Capacity used in determining bid and ask prices. Defaults to \"AGENCY\" if no value specified."""
    identifier: NotRequired[str]
    r"""Identifier of the asset (of the type specified in `identifier_type`)."""
    identifier_type: NotRequired[RetrieveQuoteResponseIdentifierType]
    r"""The identifier type of the asset for which the best bid and offer is returned. This will be the same value as what was sent on the request."""
    minimum_quantity: NotRequired[Nullable[MinimumQuantityTypedDict]]
    r"""The minimum quantity specified in the request (if any). For Fixed Income: Expressed in the par (face-value) amount and may not exceed two decimal places for USD-based currencies."""
    response_generation_time: NotRequired[Nullable[datetime]]
    r"""The time the response was generated by the system"""


class RetrieveQuoteResponse(BaseModel):
    r"""The current best bid and offer for a specified security"""

    account_id: Optional[str] = None
    r"""The account id used in calculating order costs"""

    ask_minimum_quantity: OptionalNullable[AskMinimumQuantity] = UNSET
    r"""The best ask minimum quantity. This will be absent if no ask information is available"""

    ask_prices: Optional[List[BidAskPrice]] = None
    r"""The price information of the best ask matching the request criteria. If no ask information is available at all, this will be empty. If yield information is not available, then this will only contain a PERCENTAGE_OF_PAR-typed price."""

    ask_quantity: OptionalNullable[AskQuantity] = UNSET
    r"""The best ask quantity. This will be absent if no ask information is available"""

    asset_id: Optional[str] = None
    r"""Apex Asset ID for this asset."""

    asset_type: Annotated[
        Optional[RetrieveQuoteResponseAssetType],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""The type of asset referenced by the security identifier"""

    bid_minimum_quantity: OptionalNullable[BidMinimumQuantity] = UNSET
    r"""The best bid minimum quantity. This will be absent if no bid information is available"""

    bid_prices: Optional[List[BidAskPrice]] = None
    r"""The price information of the best bid matching the request criteria. If no bid information is available at all, this will be empty. If yield information is not available, then this will only contain a PERCENTAGE_OF_PAR-typed price."""

    bid_quantity: OptionalNullable[BidQuantity] = UNSET
    r"""The best bid quantity. This will be absent if no bid information is available"""

    broker_capacity: Annotated[
        Optional[RetrieveQuoteResponseBrokerCapacity],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""Capacity used in determining bid and ask prices. Defaults to \"AGENCY\" if no value specified."""

    identifier: Optional[str] = None
    r"""Identifier of the asset (of the type specified in `identifier_type`)."""

    identifier_type: Optional[RetrieveQuoteResponseIdentifierType] = None
    r"""The identifier type of the asset for which the best bid and offer is returned. This will be the same value as what was sent on the request."""

    minimum_quantity: OptionalNullable[MinimumQuantity] = UNSET
    r"""The minimum quantity specified in the request (if any). For Fixed Income: Expressed in the par (face-value) amount and may not exceed two decimal places for USD-based currencies."""

    response_generation_time: OptionalNullable[datetime] = UNSET
    r"""The time the response was generated by the system"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "account_id",
            "ask_minimum_quantity",
            "ask_prices",
            "ask_quantity",
            "asset_id",
            "asset_type",
            "bid_minimum_quantity",
            "bid_prices",
            "bid_quantity",
            "broker_capacity",
            "identifier",
            "identifier_type",
            "minimum_quantity",
            "response_generation_time",
        ]
        nullable_fields = [
            "ask_minimum_quantity",
            "ask_quantity",
            "bid_minimum_quantity",
            "bid_quantity",
            "minimum_quantity",
            "response_generation_time",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
