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

from __future__ import annotations
from .applicationstatus import ApplicationStatus
from .creditgrantapplicationreason import CreditGrantApplicationReason
from .status import Status
from .subscriptionstatus import SubscriptionStatus
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class DtoCreditGrantApplicationResponseTypedDict(TypedDict):
    application_reason: NotRequired[CreditGrantApplicationReason]
    application_status: NotRequired[ApplicationStatus]
    applied_at: NotRequired[str]
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    credit_grant_id: NotRequired[str]
    credits: NotRequired[float]
    environment_id: NotRequired[str]
    failure_reason: NotRequired[str]
    id: NotRequired[str]
    idempotency_key: NotRequired[str]
    metadata: NotRequired[Dict[str, str]]
    period_end: NotRequired[str]
    period_start: NotRequired[str]
    retry_count: NotRequired[int]
    scheduled_for: NotRequired[str]
    status: NotRequired[Status]
    subscription_id: NotRequired[str]
    subscription_status_at_application: NotRequired[SubscriptionStatus]
    tenant_id: NotRequired[str]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]


class DtoCreditGrantApplicationResponse(BaseModel):
    application_reason: Optional[CreditGrantApplicationReason] = None

    application_status: Optional[ApplicationStatus] = None

    applied_at: Optional[str] = None

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    credit_grant_id: Optional[str] = None

    credits: Optional[float] = None

    environment_id: Optional[str] = None

    failure_reason: Optional[str] = None

    id: Optional[str] = None

    idempotency_key: Optional[str] = None

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

    period_end: Optional[str] = None

    period_start: Optional[str] = None

    retry_count: Optional[int] = None

    scheduled_for: Optional[str] = None

    status: Optional[Status] = None

    subscription_id: Optional[str] = None

    subscription_status_at_application: Optional[SubscriptionStatus] = None

    tenant_id: Optional[str] = None

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "application_reason",
                "application_status",
                "applied_at",
                "created_at",
                "created_by",
                "credit_grant_id",
                "credits",
                "environment_id",
                "failure_reason",
                "id",
                "idempotency_key",
                "metadata",
                "period_end",
                "period_start",
                "retry_count",
                "scheduled_for",
                "status",
                "subscription_id",
                "subscription_status_at_application",
                "tenant_id",
                "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
