# coding: utf-8

"""
    PAY.JP API v2

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 2.0.0
    Contact: support@pay.jp
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from payjpv2.models.checkout_session_mode import CheckoutSessionMode
from payjpv2.models.checkout_session_status import CheckoutSessionStatus
from payjpv2.models.checkout_session_submit_type import CheckoutSessionSubmitType
from payjpv2.models.checkout_session_ui_mode import CheckoutSessionUIMode
from payjpv2.models.currency import Currency
from payjpv2.models.locale import Locale
from payjpv2.models.metadata_value import MetadataValue
from payjpv2.models.payment_method_types import PaymentMethodTypes
from typing import Optional, Set
from typing_extensions import Self

class CheckoutSessionDetailsResponse(BaseModel):
    """
    CheckoutSessionDetailsResponse
    """ # noqa: E501
    id: StrictStr = Field(description="ID")
    object: Optional[StrictStr] = 'checkout.session'
    livemode: StrictBool = Field(description="本番環境かどうか")
    amount_subtotal: Optional[StrictInt]
    amount_total: Optional[StrictInt]
    cancel_url: Optional[StrictStr]
    customer_id: Optional[StrictStr]
    customer_email: Optional[StrictStr]
    expires_at: Optional[datetime]
    currency: Currency = Field(description="価格の通貨。現在は `jpy` のみサポートしています。")
    locale: Optional[Locale]
    payment_flow_id: Optional[StrictStr] = None
    payment_method_types: Optional[List[PaymentMethodTypes]]
    payment_method_options: Optional[Dict[str, Any]]
    setup_flow_id: Optional[StrictStr] = None
    submit_type: Optional[CheckoutSessionSubmitType]
    mode: CheckoutSessionMode = Field(description="Checkout Session のモード  | 指定できる値 | |:---| | **payment**: 支払いモードでCheckout Sessionを作成します。 | | **setup**: セットアップモードでCheckout Sessionを作成します。 | ")
    ui_mode: CheckoutSessionUIMode = Field(description="Checkout Session の UI モード。デフォルトは `hosted` です。<br>  | 指定できる値 | |:---| | **hosted**: PAY.JPでホスティングしている画面を使用します。 | ")
    created_at: datetime = Field(description="作成日時 (UTC, ISO 8601 形式)")
    updated_at: datetime = Field(description="更新日時 (UTC, ISO 8601 形式)")
    metadata: Dict[str, MetadataValue] = Field(description="メタデータ")
    status: CheckoutSessionStatus = Field(description="チェックアウトセッションのステータス")
    success_url: Optional[StrictStr]
    url: StrictStr = Field(description="URL")
    __properties: ClassVar[List[str]] = ["id", "object", "livemode", "amount_subtotal", "amount_total", "cancel_url", "customer_id", "customer_email", "expires_at", "currency", "locale", "payment_flow_id", "payment_method_types", "payment_method_options", "setup_flow_id", "submit_type", "mode", "ui_mode", "created_at", "updated_at", "metadata", "status", "success_url", "url"]

    @field_validator('object')
    def object_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['checkout.session']):
            raise ValueError("must be one of enum values ('checkout.session')")
        return value

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.model_dump(by_alias=True, exclude_unset=True))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of CheckoutSessionDetailsResponse from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each value in metadata (dict)
        _field_dict = {}
        if self.metadata:
            for _key_metadata in self.metadata:
                if self.metadata[_key_metadata]:
                    _field_dict[_key_metadata] = self.metadata[_key_metadata].to_dict()
            _dict['metadata'] = _field_dict
        # set to None if amount_subtotal (nullable) is None
        # and model_fields_set contains the field
        if self.amount_subtotal is None and "amount_subtotal" in self.model_fields_set:
            _dict['amount_subtotal'] = None

        # set to None if amount_total (nullable) is None
        # and model_fields_set contains the field
        if self.amount_total is None and "amount_total" in self.model_fields_set:
            _dict['amount_total'] = None

        # set to None if cancel_url (nullable) is None
        # and model_fields_set contains the field
        if self.cancel_url is None and "cancel_url" in self.model_fields_set:
            _dict['cancel_url'] = None

        # set to None if customer_id (nullable) is None
        # and model_fields_set contains the field
        if self.customer_id is None and "customer_id" in self.model_fields_set:
            _dict['customer_id'] = None

        # set to None if customer_email (nullable) is None
        # and model_fields_set contains the field
        if self.customer_email is None and "customer_email" in self.model_fields_set:
            _dict['customer_email'] = None

        # set to None if expires_at (nullable) is None
        # and model_fields_set contains the field
        if self.expires_at is None and "expires_at" in self.model_fields_set:
            _dict['expires_at'] = None

        # set to None if locale (nullable) is None
        # and model_fields_set contains the field
        if self.locale is None and "locale" in self.model_fields_set:
            _dict['locale'] = None

        # set to None if payment_flow_id (nullable) is None
        # and model_fields_set contains the field
        if self.payment_flow_id is None and "payment_flow_id" in self.model_fields_set:
            _dict['payment_flow_id'] = None

        # set to None if payment_method_types (nullable) is None
        # and model_fields_set contains the field
        if self.payment_method_types is None and "payment_method_types" in self.model_fields_set:
            _dict['payment_method_types'] = None

        # set to None if payment_method_options (nullable) is None
        # and model_fields_set contains the field
        if self.payment_method_options is None and "payment_method_options" in self.model_fields_set:
            _dict['payment_method_options'] = None

        # set to None if setup_flow_id (nullable) is None
        # and model_fields_set contains the field
        if self.setup_flow_id is None and "setup_flow_id" in self.model_fields_set:
            _dict['setup_flow_id'] = None

        # set to None if submit_type (nullable) is None
        # and model_fields_set contains the field
        if self.submit_type is None and "submit_type" in self.model_fields_set:
            _dict['submit_type'] = None

        # set to None if success_url (nullable) is None
        # and model_fields_set contains the field
        if self.success_url is None and "success_url" in self.model_fields_set:
            _dict['success_url'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CheckoutSessionDetailsResponse from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "object": obj.get("object") if obj.get("object") is not None else 'checkout.session',
            "livemode": obj.get("livemode"),
            "amount_subtotal": obj.get("amount_subtotal"),
            "amount_total": obj.get("amount_total"),
            "cancel_url": obj.get("cancel_url"),
            "customer_id": obj.get("customer_id"),
            "customer_email": obj.get("customer_email"),
            "expires_at": obj.get("expires_at"),
            "currency": obj.get("currency"),
            "locale": obj.get("locale"),
            "payment_flow_id": obj.get("payment_flow_id"),
            "payment_method_types": obj.get("payment_method_types"),
            "payment_method_options": obj.get("payment_method_options"),
            "setup_flow_id": obj.get("setup_flow_id"),
            "submit_type": obj.get("submit_type"),
            "mode": obj.get("mode"),
            "ui_mode": obj.get("ui_mode"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "metadata": dict(
                (_k, MetadataValue.from_dict(_v))
                for _k, _v in obj["metadata"].items()
            )
            if obj.get("metadata") is not None
            else None,
            "status": obj.get("status"),
            "success_url": obj.get("success_url"),
            "url": obj.get("url")
        })
        return _obj


