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

from __future__ import annotations
from .creditgrantcadence import CreditGrantCadence
from .creditgrantexpirydurationunit import CreditGrantExpiryDurationUnit
from .creditgrantexpirytype import CreditGrantExpiryType
from .creditgrantperiod import CreditGrantPeriod
from .creditgrantscope import CreditGrantScope
from .status import Status
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class DtoCreditGrantResponseTypedDict(TypedDict):
    cadence: NotRequired[CreditGrantCadence]
    conversion_rate: NotRequired[str]
    r"""amount in the currency =  number of credits * conversion_rate
    ex if conversion_rate is 1, then 1 USD = 1 credit
    ex if conversion_rate is 2, then 1 USD = 0.5 credits
    ex if conversion_rate is 0.5, then 1 USD = 2 credits
    """
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    credit_grant_anchor: NotRequired[str]
    credits: NotRequired[str]
    end_date: NotRequired[str]
    environment_id: NotRequired[str]
    expiration_duration: NotRequired[int]
    expiration_duration_unit: NotRequired[CreditGrantExpiryDurationUnit]
    expiration_type: NotRequired[CreditGrantExpiryType]
    id: NotRequired[str]
    metadata: NotRequired[Dict[str, str]]
    name: NotRequired[str]
    period: NotRequired[CreditGrantPeriod]
    period_count: NotRequired[int]
    plan_id: NotRequired[str]
    priority: NotRequired[int]
    scope: NotRequired[CreditGrantScope]
    start_date: NotRequired[str]
    status: NotRequired[Status]
    subscription_id: NotRequired[str]
    tenant_id: NotRequired[str]
    topup_conversion_rate: NotRequired[str]
    r"""topup_conversion_rate is the conversion rate for the topup to the currency
    ex if topup_conversion_rate is 1, then 1 USD = 1 credit
    ex if topup_conversion_rate is 2, then 1 USD = 0.5 credits
    ex if topup_conversion_rate is 0.5, then 1 USD = 2 credits
    """
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]


class DtoCreditGrantResponse(BaseModel):
    cadence: Optional[CreditGrantCadence] = None

    conversion_rate: Optional[str] = None
    r"""amount in the currency =  number of credits * conversion_rate
    ex if conversion_rate is 1, then 1 USD = 1 credit
    ex if conversion_rate is 2, then 1 USD = 0.5 credits
    ex if conversion_rate is 0.5, then 1 USD = 2 credits
    """

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    credit_grant_anchor: Optional[str] = None

    credits: Optional[str] = None

    end_date: Optional[str] = None

    environment_id: Optional[str] = None

    expiration_duration: Optional[int] = None

    expiration_duration_unit: Optional[CreditGrantExpiryDurationUnit] = None

    expiration_type: Optional[CreditGrantExpiryType] = None

    id: Optional[str] = None

    metadata: Optional[Dict[str, str]] = None

    name: Optional[str] = None

    period: Optional[CreditGrantPeriod] = None

    period_count: Optional[int] = None

    plan_id: Optional[str] = None

    priority: Optional[int] = None

    scope: Optional[CreditGrantScope] = None

    start_date: Optional[str] = None

    status: Optional[Status] = None

    subscription_id: Optional[str] = None

    tenant_id: Optional[str] = None

    topup_conversion_rate: Optional[str] = None
    r"""topup_conversion_rate is the conversion rate for the topup to the currency
    ex if topup_conversion_rate is 1, then 1 USD = 1 credit
    ex if topup_conversion_rate is 2, then 1 USD = 0.5 credits
    ex if topup_conversion_rate is 0.5, then 1 USD = 2 credits
    """

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "cadence",
                "conversion_rate",
                "created_at",
                "created_by",
                "credit_grant_anchor",
                "credits",
                "end_date",
                "environment_id",
                "expiration_duration",
                "expiration_duration_unit",
                "expiration_type",
                "id",
                "metadata",
                "name",
                "period",
                "period_count",
                "plan_id",
                "priority",
                "scope",
                "start_date",
                "status",
                "subscription_id",
                "tenant_id",
                "topup_conversion_rate",
                "updated_at",
                "updated_by",
            ]
        )
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
