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

from __future__ import annotations
from .executedprice import ExecutedPrice, ExecutedPriceTypedDict
from ascend_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from datetime import datetime
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class AccruedInterestAmountTypedDict(TypedDict):
    r"""The amount of accrued interest exchanged in this execution. Will only be present for orders of Fixed Income assets."""

    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 AccruedInterestAmount(BaseModel):
    r"""The amount of accrued interest exchanged in this execution. Will only be present for orders of Fixed Income assets."""

    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 GrossCreditAmountTypedDict(TypedDict):
    r"""The net currency amount exchanged in this transaction, in the order currency. Will only be present for orders of Fixed Income assets."""

    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 GrossCreditAmount(BaseModel):
    r"""The net currency amount exchanged in this transaction, in the order currency. Will only be present for orders of Fixed Income assets."""

    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 PrevailingMarketPriceTypedDict(TypedDict):
    r"""The prevailing market price of the asset, without fees or commissions. Will only be present for orders of Fixed Income assets."""

    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 PrevailingMarketPrice(BaseModel):
    r"""The prevailing market price of the asset, without fees or commissions. Will only be present for orders of Fixed Income assets."""

    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 QuantityTypedDict(TypedDict):
    r"""The quantity of the order. For Equities: measured in shares. For Fixed Income assets: measured in the face value of the currency of the order."""

    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 Quantity(BaseModel):
    r"""The quantity of the order. For Equities: measured in shares. For Fixed Income assets: measured in the face value of the currency of the order."""

    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 ExecutionsTypedDict(TypedDict):
    r"""Details of an individual execution within an order"""

    accrued_interest_amount: NotRequired[Nullable[AccruedInterestAmountTypedDict]]
    r"""The amount of accrued interest exchanged in this execution. Will only be present for orders of Fixed Income assets."""
    executed_prices: NotRequired[List[ExecutedPriceTypedDict]]
    r"""The prices at which the order was executed. For Equities: there will be one price measured in PRICE_PER_UNIT (using the order currency). For Fixed Income assets: there will always be an entry measured in the PERCENTAGE_OF_PAR (100 X cost / total par value), and there may be additional entries measured in yield."""
    executed_time: NotRequired[Nullable[datetime]]
    r"""The timestamp that this fill was transacted at the market"""
    gross_credit_amount: NotRequired[Nullable[GrossCreditAmountTypedDict]]
    r"""The net currency amount exchanged in this transaction, in the order currency. Will only be present for orders of Fixed Income assets."""
    prevailing_market_price: NotRequired[Nullable[PrevailingMarketPriceTypedDict]]
    r"""The prevailing market price of the asset, without fees or commissions. Will only be present for orders of Fixed Income assets."""
    quantity: NotRequired[Nullable[QuantityTypedDict]]
    r"""The quantity of the order. For Equities: measured in shares. For Fixed Income assets: measured in the face value of the currency of the order."""


class Executions(BaseModel):
    r"""Details of an individual execution within an order"""

    accrued_interest_amount: OptionalNullable[AccruedInterestAmount] = UNSET
    r"""The amount of accrued interest exchanged in this execution. Will only be present for orders of Fixed Income assets."""

    executed_prices: Optional[List[ExecutedPrice]] = None
    r"""The prices at which the order was executed. For Equities: there will be one price measured in PRICE_PER_UNIT (using the order currency). For Fixed Income assets: there will always be an entry measured in the PERCENTAGE_OF_PAR (100 X cost / total par value), and there may be additional entries measured in yield."""

    executed_time: OptionalNullable[datetime] = UNSET
    r"""The timestamp that this fill was transacted at the market"""

    gross_credit_amount: OptionalNullable[GrossCreditAmount] = UNSET
    r"""The net currency amount exchanged in this transaction, in the order currency. Will only be present for orders of Fixed Income assets."""

    prevailing_market_price: OptionalNullable[PrevailingMarketPrice] = UNSET
    r"""The prevailing market price of the asset, without fees or commissions. Will only be present for orders of Fixed Income assets."""

    quantity: OptionalNullable[Quantity] = UNSET
    r"""The quantity of the order. For Equities: measured in shares. For Fixed Income assets: measured in the face value of the currency of the order."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "accrued_interest_amount",
            "executed_prices",
            "executed_time",
            "gross_credit_amount",
            "prevailing_market_price",
            "quantity",
        ]
        nullable_fields = [
            "accrued_interest_amount",
            "executed_time",
            "gross_credit_amount",
            "prevailing_market_price",
            "quantity",
        ]
        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
