# coding: utf-8

"""
    Ringer Business API - Payments

    This API provides endpoints for managing payments for a Ringer Business account. It allows developers to: - List past payments made on the account. - Create a new payment, typically using a stored payment method (e.g., credit card).  Payments are processed securely. Specific payment method details are handled via their respective APIs (e.g., Credit Cards API). 

    The version of the OpenAPI document: 1.0.0
    Contact: support@ringer.tel
    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 import Optional, Set
from typing_extensions import Self

class PaymentCore(BaseModel):
    """
    PaymentCore
    """ # noqa: E501
    id: StrictInt = Field(description="Unique identifier for the payment record.")
    amount_in_dollars: StrictStr = Field(description="The amount of the payment in dollars.")
    currency: StrictStr = Field(description="Three-letter ISO currency code (e.g., USD, CAD, EUR).")
    status: StrictStr = Field(description="The status of the payment transaction.")
    success: Optional[StrictBool] = Field(default=None, description="Indicates if the payment transaction was successful.")
    payment_method_summary: Optional[StrictStr] = Field(default=None, description="A brief summary of the payment method used (e.g., \"Visa ending in 1234\").")
    transaction_id: Optional[StrictStr] = Field(default=None, description="The unique identifier for the transaction from the payment processor.")
    created_at: datetime = Field(description="Timestamp of when the payment was created/processed.")
    __properties: ClassVar[List[str]] = ["id", "amount_in_dollars", "currency", "status", "success", "payment_method_summary", "transaction_id", "created_at"]

    @field_validator('status')
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['pending', 'succeeded', 'failed', 'requires_action', 'canceled']):
            raise ValueError("must be one of enum values ('pending', 'succeeded', 'failed', 'requires_action', 'canceled')")
        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"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of PaymentCore 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,
        )
        # set to None if payment_method_summary (nullable) is None
        # and model_fields_set contains the field
        if self.payment_method_summary is None and "payment_method_summary" in self.model_fields_set:
            _dict['payment_method_summary'] = None

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of PaymentCore 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"),
            "amount_in_dollars": obj.get("amount_in_dollars"),
            "currency": obj.get("currency") if obj.get("currency") is not None else 'USD',
            "status": obj.get("status"),
            "success": obj.get("success"),
            "payment_method_summary": obj.get("payment_method_summary"),
            "transaction_id": obj.get("transaction_id"),
            "created_at": obj.get("created_at")
        })
        return _obj


