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

from __future__ import annotations
from .markprice import MarkPrice, MarkPriceTypedDict
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 RetrieveFixedIncomeMarksResponseAssetMarkAccruedInterestAmountTypedDict(
    TypedDict
):
    r"""The amount of accrued interest estimated to be exchanged given the requested quantity. Measured in a USD value with 2-decimal places of precision."""

    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 RetrieveFixedIncomeMarksResponseAssetMarkAccruedInterestAmount(BaseModel):
    r"""The amount of accrued interest estimated to be exchanged given the requested quantity. Measured in a USD value with 2-decimal places of precision."""

    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 RetrieveFixedIncomeMarksResponseAssetMarkIdentifierType(str, Enum):
    r"""The identifier type of the asset being sought. This will be the same value as what was sent on the request."""

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


class MarkAbsenceReason(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""When marks are found and returned, this will be unspecified. If the asset was found, but no pricing data is returned, then: this will denote the reason, the marks[] list will be empty, and the accrued_interest_amount will not be present."""

    MARK_ABSENCE_REASON_UNSPECIFIED = "MARK_ABSENCE_REASON_UNSPECIFIED"
    NOT_PRICED = "NOT_PRICED"
    NOT_TRADABLE = "NOT_TRADABLE"


class RetrieveFixedIncomeMarksResponseAssetMarkTypedDict(TypedDict):
    r"""Mark data for a specific asset"""

    accrued_interest_amount: NotRequired[
        Nullable[
            RetrieveFixedIncomeMarksResponseAssetMarkAccruedInterestAmountTypedDict
        ]
    ]
    r"""The amount of accrued interest estimated to be exchanged given the requested quantity. Measured in a USD value with 2-decimal places of precision."""
    asset_id: NotRequired[str]
    r"""Apex Asset ID for this asset."""
    identifier: NotRequired[str]
    r"""Identifier of the asset (of the type specified in `identifier_type`)."""
    identifier_type: NotRequired[
        RetrieveFixedIncomeMarksResponseAssetMarkIdentifierType
    ]
    r"""The identifier type of the asset being sought. This will be the same value as what was sent on the request."""
    mark_absence_reason: NotRequired[MarkAbsenceReason]
    r"""When marks are found and returned, this will be unspecified. If the asset was found, but no pricing data is returned, then: this will denote the reason, the marks[] list will be empty, and the accrued_interest_amount will not be present."""
    mark_generation_time: NotRequired[Nullable[datetime]]
    r"""The time this mark data was generated"""
    marks: NotRequired[List[MarkPriceTypedDict]]
    r"""The set of marks available for this asset. If this is non-empty, then it will always contain a PERCENTAGE_OF_PAR typed price in it. Yield prices may not always be available, but never be present without a percentage of par value also returned."""


class RetrieveFixedIncomeMarksResponseAssetMark(BaseModel):
    r"""Mark data for a specific asset"""

    accrued_interest_amount: OptionalNullable[
        RetrieveFixedIncomeMarksResponseAssetMarkAccruedInterestAmount
    ] = UNSET
    r"""The amount of accrued interest estimated to be exchanged given the requested quantity. Measured in a USD value with 2-decimal places of precision."""

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

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

    identifier_type: Optional[
        RetrieveFixedIncomeMarksResponseAssetMarkIdentifierType
    ] = None
    r"""The identifier type of the asset being sought. This will be the same value as what was sent on the request."""

    mark_absence_reason: Annotated[
        Optional[MarkAbsenceReason], PlainValidator(validate_open_enum(False))
    ] = None
    r"""When marks are found and returned, this will be unspecified. If the asset was found, but no pricing data is returned, then: this will denote the reason, the marks[] list will be empty, and the accrued_interest_amount will not be present."""

    mark_generation_time: OptionalNullable[datetime] = UNSET
    r"""The time this mark data was generated"""

    marks: Optional[List[MarkPrice]] = None
    r"""The set of marks available for this asset. If this is non-empty, then it will always contain a PERCENTAGE_OF_PAR typed price in it. Yield prices may not always be available, but never be present without a percentage of par value also returned."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "accrued_interest_amount",
            "asset_id",
            "identifier",
            "identifier_type",
            "mark_absence_reason",
            "mark_generation_time",
            "marks",
        ]
        nullable_fields = ["accrued_interest_amount", "mark_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
