# 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 Any, Dict, Optional
from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr
from conekta.models.charge_response_channel import ChargeResponseChannel
from conekta.models.order_response_charges import OrderResponseCharges
from conekta.models.order_response_checkout import OrderResponseCheckout
from conekta.models.order_response_customer_info import OrderResponseCustomerInfo
from conekta.models.order_response_discount_lines import OrderResponseDiscountLines
from conekta.models.order_response_fiscal_entity import OrderResponseFiscalEntity
from conekta.models.order_response_products import OrderResponseProducts
from conekta.models.order_response_shipping_contact import OrderResponseShippingContact

class OrderResponse(BaseModel):
    """
    order response
    """
    amount: Optional[StrictInt] = Field(None, description="The total amount to be collected in cents")
    amount_refunded: Optional[StrictInt] = Field(None, description="The total amount refunded in cents")
    channel: Optional[ChargeResponseChannel] = None
    charges: Optional[OrderResponseCharges] = None
    checkout: Optional[OrderResponseCheckout] = None
    created_at: Optional[StrictInt] = Field(None, description="The time at which the object was created in seconds since the Unix epoch")
    currency: Optional[StrictStr] = Field(None, description="The three-letter ISO 4217 currency code. The currency of the order.")
    customer_info: Optional[OrderResponseCustomerInfo] = None
    discount_lines: Optional[OrderResponseDiscountLines] = None
    fiscal_entity: Optional[OrderResponseFiscalEntity] = None
    id: Optional[StrictStr] = None
    is_refundable: Optional[StrictBool] = None
    line_items: Optional[OrderResponseProducts] = None
    livemode: Optional[StrictBool] = Field(None, description="Whether the object exists in live mode or test mode")
    metadata: Optional[Dict[str, Any]] = Field(None, description="Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format.")
    object: Optional[StrictStr] = Field(None, description="String representing the object’s type. Objects of the same type share the same value.")
    payment_status: Optional[StrictStr] = Field(None, description="The payment status of the order.")
    processing_mode: Optional[StrictStr] = Field(None, description="Indicates the processing mode for the order, either ecommerce, recurrent or validation.")
    shipping_contact: Optional[OrderResponseShippingContact] = None
    updated_at: Optional[StrictInt] = Field(None, description="The time at which the object was last updated in seconds since the Unix epoch")
    __properties = ["amount", "amount_refunded", "channel", "charges", "checkout", "created_at", "currency", "customer_info", "discount_lines", "fiscal_entity", "id", "is_refundable", "line_items", "livemode", "metadata", "object", "payment_status", "processing_mode", "shipping_contact", "updated_at"]

    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) -> OrderResponse:
        """Create an instance of OrderResponse 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 charges
        if self.charges:
            _dict['charges'] = self.charges.to_dict()
        # override the default output from pydantic by calling `to_dict()` of checkout
        if self.checkout:
            _dict['checkout'] = self.checkout.to_dict()
        # override the default output from pydantic by calling `to_dict()` of customer_info
        if self.customer_info:
            _dict['customer_info'] = self.customer_info.to_dict()
        # override the default output from pydantic by calling `to_dict()` of discount_lines
        if self.discount_lines:
            _dict['discount_lines'] = self.discount_lines.to_dict()
        # override the default output from pydantic by calling `to_dict()` of fiscal_entity
        if self.fiscal_entity:
            _dict['fiscal_entity'] = self.fiscal_entity.to_dict()
        # override the default output from pydantic by calling `to_dict()` of line_items
        if self.line_items:
            _dict['line_items'] = self.line_items.to_dict()
        # override the default output from pydantic by calling `to_dict()` of shipping_contact
        if self.shipping_contact:
            _dict['shipping_contact'] = self.shipping_contact.to_dict()
        return _dict

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

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

        _obj = OrderResponse.parse_obj({
            "amount": obj.get("amount"),
            "amount_refunded": obj.get("amount_refunded"),
            "channel": ChargeResponseChannel.from_dict(obj.get("channel")) if obj.get("channel") is not None else None,
            "charges": OrderResponseCharges.from_dict(obj.get("charges")) if obj.get("charges") is not None else None,
            "checkout": OrderResponseCheckout.from_dict(obj.get("checkout")) if obj.get("checkout") is not None else None,
            "created_at": obj.get("created_at"),
            "currency": obj.get("currency"),
            "customer_info": OrderResponseCustomerInfo.from_dict(obj.get("customer_info")) if obj.get("customer_info") is not None else None,
            "discount_lines": OrderResponseDiscountLines.from_dict(obj.get("discount_lines")) if obj.get("discount_lines") is not None else None,
            "fiscal_entity": OrderResponseFiscalEntity.from_dict(obj.get("fiscal_entity")) if obj.get("fiscal_entity") is not None else None,
            "id": obj.get("id"),
            "is_refundable": obj.get("is_refundable"),
            "line_items": OrderResponseProducts.from_dict(obj.get("line_items")) if obj.get("line_items") is not None else None,
            "livemode": obj.get("livemode"),
            "metadata": obj.get("metadata"),
            "object": obj.get("object"),
            "payment_status": obj.get("payment_status"),
            "processing_mode": obj.get("processing_mode"),
            "shipping_contact": OrderResponseShippingContact.from_dict(obj.get("shipping_contact")) if obj.get("shipping_contact") is not None else None,
            "updated_at": obj.get("updated_at")
        })
        return _obj

