# coding: utf-8

"""
    Conekta API

    Conekta sdk  # noqa: E501

    The version of the OpenAPI document: 2.1.0
    Contact: engineering@conekta.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""


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


from typing import Optional
from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr
from conekta.models.charge_response_channel import ChargeResponseChannel
from conekta.models.charge_response_payment_method import ChargeResponsePaymentMethod
from conekta.models.charge_response_refunds import ChargeResponseRefunds

class ChargesDataResponse(BaseModel):
    """
    ChargesDataResponse
    """
    amount: Optional[StrictInt] = None
    channel: Optional[ChargeResponseChannel] = None
    created_at: Optional[StrictInt] = None
    currency: Optional[StrictStr] = None
    customer_id: Optional[StrictStr] = None
    description: Optional[StrictStr] = None
    device_fingerprint: Optional[StrictStr] = None
    failure_code: Optional[StrictStr] = None
    failure_message: Optional[StrictStr] = None
    fee: Optional[StrictInt] = None
    id: Optional[StrictStr] = None
    livemode: Optional[StrictBool] = None
    object: Optional[StrictStr] = None
    order_id: Optional[StrictStr] = None
    paid_at: Optional[StrictInt] = None
    payment_method: Optional[ChargeResponsePaymentMethod] = None
    reference_id: Optional[StrictStr] = Field(None, description="Reference ID of the charge")
    refunds: Optional[ChargeResponseRefunds] = None
    status: Optional[StrictStr] = None
    __properties = ["amount", "channel", "created_at", "currency", "customer_id", "description", "device_fingerprint", "failure_code", "failure_message", "fee", "id", "livemode", "object", "order_id", "paid_at", "payment_method", "reference_id", "refunds", "status"]

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

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

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

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

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of channel
        if self.channel:
            _dict['channel'] = self.channel.to_dict()
        # override the default output from pydantic by calling `to_dict()` of payment_method
        if self.payment_method:
            _dict['payment_method'] = self.payment_method.to_dict()
        # override the default output from pydantic by calling `to_dict()` of refunds
        if self.refunds:
            _dict['refunds'] = self.refunds.to_dict()
        # set to None if paid_at (nullable) is None
        # and __fields_set__ contains the field
        if self.paid_at is None and "paid_at" in self.__fields_set__:
            _dict['paid_at'] = None

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> ChargesDataResponse:
        """Create an instance of ChargesDataResponse from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return ChargesDataResponse.parse_obj(obj)

        _obj = ChargesDataResponse.parse_obj({
            "amount": obj.get("amount"),
            "channel": ChargeResponseChannel.from_dict(obj.get("channel")) if obj.get("channel") is not None else None,
            "created_at": obj.get("created_at"),
            "currency": obj.get("currency"),
            "customer_id": obj.get("customer_id"),
            "description": obj.get("description"),
            "device_fingerprint": obj.get("device_fingerprint"),
            "failure_code": obj.get("failure_code"),
            "failure_message": obj.get("failure_message"),
            "fee": obj.get("fee"),
            "id": obj.get("id"),
            "livemode": obj.get("livemode"),
            "object": obj.get("object"),
            "order_id": obj.get("order_id"),
            "paid_at": obj.get("paid_at"),
            "payment_method": ChargeResponsePaymentMethod.from_dict(obj.get("payment_method")) if obj.get("payment_method") is not None else None,
            "reference_id": obj.get("reference_id"),
            "refunds": ChargeResponseRefunds.from_dict(obj.get("refunds")) if obj.get("refunds") is not None else None,
            "status": obj.get("status")
        })
        return _obj

