# 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 typing_extensions import Annotated
from payjpv2.models.currency import Currency
from payjpv2.models.payment_method_types import PaymentMethodTypes
from payjpv2.models.payment_transaction_type import PaymentTransactionType
from typing import Optional, Set
from typing_extensions import Self

class PaymentTransactionResponse(BaseModel):
    """
    PaymentTransactionResponse
    """ # noqa: E501
    object: Optional[StrictStr] = 'payment_transaction'
    id: StrictStr = Field(description="決済トランザクション ID")
    livemode: StrictBool = Field(description="本番環境かどうか")
    resource_id: StrictStr = Field(description="PaymentTransaction 生成の元になったリソースの ID")
    amount: StrictInt = Field(description="金額")
    currency: Currency = Field(description="通貨")
    fee_rate: Annotated[str, Field(strict=True)] = Field(description="手数料率")
    fee: StrictInt = Field(description="手数料")
    type: PaymentTransactionType = Field(description="PaymentTransaction の種類  | 値 | |:---| | **payment**: 支払い | | **refund**: 返金 | | **chargeback**: チャージバック | | **chargeback_cancel**: チャージバックのキャンセル | ")
    payment_method_type: PaymentMethodTypes = Field(description="支払い方法の種類")
    term_id: StrictStr = Field(description="集計区間 ID")
    created_at: datetime = Field(description="作成日時 (UTC, ISO 8601 形式)")
    updated_at: datetime = Field(description="更新日時 (UTC, ISO 8601 形式)")
    __properties: ClassVar[List[str]] = ["object", "id", "livemode", "resource_id", "amount", "currency", "fee_rate", "fee", "type", "payment_method_type", "term_id", "created_at", "updated_at"]

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

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

    @field_validator('fee_rate')
    def fee_rate_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$", value):
            raise ValueError(r"must validate the regular expression /^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/")
        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 PaymentTransactionResponse 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "object": obj.get("object") if obj.get("object") is not None else 'payment_transaction',
            "id": obj.get("id"),
            "livemode": obj.get("livemode"),
            "resource_id": obj.get("resource_id"),
            "amount": obj.get("amount"),
            "currency": obj.get("currency"),
            "fee_rate": obj.get("fee_rate"),
            "fee": obj.get("fee"),
            "type": obj.get("type"),
            "payment_method_type": obj.get("payment_method_type"),
            "term_id": obj.get("term_id"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


