# coding: utf-8

"""
    Neurograph Core

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

    The version of the OpenAPI document: 1.0
    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 pydantic import BaseModel, ConfigDict, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from neurograph.v1.models.pgtype_text import PgtypeText
from neurograph.v1.models.pgtype_timestamp import PgtypeTimestamp
from typing import Optional, Set
from typing_extensions import Self

class DbKnowledgeOrder(BaseModel):
    """
    DbKnowledgeOrder
    """ # noqa: E501
    billing_address_hash: Optional[PgtypeText] = None
    billing_address_json: Optional[List[StrictInt]] = None
    cancelled_at: Optional[PgtypeTimestamp] = None
    channel: Optional[StrictStr] = None
    client_id: Optional[StrictStr] = None
    closed_at: Optional[PgtypeTimestamp] = None
    currency: Optional[StrictStr] = None
    customer_entity_id: Optional[PgtypeText] = None
    discount_amount: Optional[Union[StrictFloat, StrictInt]] = None
    email_at_order: Optional[PgtypeText] = None
    entity_id: Optional[StrictStr] = None
    ext_order_id: Optional[PgtypeText] = None
    ext_order_number: Optional[PgtypeText] = None
    ext_store_id: Optional[PgtypeText] = None
    financial_status: Optional[StrictStr] = None
    fulfillment_status: Optional[StrictStr] = None
    phone_at_order: Optional[PgtypeText] = None
    placed_at: Optional[PgtypeTimestamp] = None
    shipping_address_hash: Optional[PgtypeText] = None
    shipping_address_json: Optional[List[StrictInt]] = None
    shipping_amount: Optional[Union[StrictFloat, StrictInt]] = None
    source_name: Optional[StrictStr] = None
    status: Optional[StrictStr] = None
    store_entity_id: Optional[PgtypeText] = None
    subtotal_amount: Optional[Union[StrictFloat, StrictInt]] = None
    tax_amount: Optional[Union[StrictFloat, StrictInt]] = None
    total_amount: Optional[Union[StrictFloat, StrictInt]] = None
    __properties: ClassVar[List[str]] = ["billing_address_hash", "billing_address_json", "cancelled_at", "channel", "client_id", "closed_at", "currency", "customer_entity_id", "discount_amount", "email_at_order", "entity_id", "ext_order_id", "ext_order_number", "ext_store_id", "financial_status", "fulfillment_status", "phone_at_order", "placed_at", "shipping_address_hash", "shipping_address_json", "shipping_amount", "source_name", "status", "store_entity_id", "subtotal_amount", "tax_amount", "total_amount"]

    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 DbKnowledgeOrder 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 billing_address_hash
        if self.billing_address_hash:
            _dict['billing_address_hash'] = self.billing_address_hash.to_dict()
        # override the default output from pydantic by calling `to_dict()` of cancelled_at
        if self.cancelled_at:
            _dict['cancelled_at'] = self.cancelled_at.to_dict()
        # override the default output from pydantic by calling `to_dict()` of closed_at
        if self.closed_at:
            _dict['closed_at'] = self.closed_at.to_dict()
        # override the default output from pydantic by calling `to_dict()` of customer_entity_id
        if self.customer_entity_id:
            _dict['customer_entity_id'] = self.customer_entity_id.to_dict()
        # override the default output from pydantic by calling `to_dict()` of email_at_order
        if self.email_at_order:
            _dict['email_at_order'] = self.email_at_order.to_dict()
        # override the default output from pydantic by calling `to_dict()` of ext_order_id
        if self.ext_order_id:
            _dict['ext_order_id'] = self.ext_order_id.to_dict()
        # override the default output from pydantic by calling `to_dict()` of ext_order_number
        if self.ext_order_number:
            _dict['ext_order_number'] = self.ext_order_number.to_dict()
        # override the default output from pydantic by calling `to_dict()` of ext_store_id
        if self.ext_store_id:
            _dict['ext_store_id'] = self.ext_store_id.to_dict()
        # override the default output from pydantic by calling `to_dict()` of phone_at_order
        if self.phone_at_order:
            _dict['phone_at_order'] = self.phone_at_order.to_dict()
        # override the default output from pydantic by calling `to_dict()` of placed_at
        if self.placed_at:
            _dict['placed_at'] = self.placed_at.to_dict()
        # override the default output from pydantic by calling `to_dict()` of shipping_address_hash
        if self.shipping_address_hash:
            _dict['shipping_address_hash'] = self.shipping_address_hash.to_dict()
        # override the default output from pydantic by calling `to_dict()` of store_entity_id
        if self.store_entity_id:
            _dict['store_entity_id'] = self.store_entity_id.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "billing_address_hash": PgtypeText.from_dict(obj["billing_address_hash"]) if obj.get("billing_address_hash") is not None else None,
            "billing_address_json": obj.get("billing_address_json"),
            "cancelled_at": PgtypeTimestamp.from_dict(obj["cancelled_at"]) if obj.get("cancelled_at") is not None else None,
            "channel": obj.get("channel"),
            "client_id": obj.get("client_id"),
            "closed_at": PgtypeTimestamp.from_dict(obj["closed_at"]) if obj.get("closed_at") is not None else None,
            "currency": obj.get("currency"),
            "customer_entity_id": PgtypeText.from_dict(obj["customer_entity_id"]) if obj.get("customer_entity_id") is not None else None,
            "discount_amount": obj.get("discount_amount"),
            "email_at_order": PgtypeText.from_dict(obj["email_at_order"]) if obj.get("email_at_order") is not None else None,
            "entity_id": obj.get("entity_id"),
            "ext_order_id": PgtypeText.from_dict(obj["ext_order_id"]) if obj.get("ext_order_id") is not None else None,
            "ext_order_number": PgtypeText.from_dict(obj["ext_order_number"]) if obj.get("ext_order_number") is not None else None,
            "ext_store_id": PgtypeText.from_dict(obj["ext_store_id"]) if obj.get("ext_store_id") is not None else None,
            "financial_status": obj.get("financial_status"),
            "fulfillment_status": obj.get("fulfillment_status"),
            "phone_at_order": PgtypeText.from_dict(obj["phone_at_order"]) if obj.get("phone_at_order") is not None else None,
            "placed_at": PgtypeTimestamp.from_dict(obj["placed_at"]) if obj.get("placed_at") is not None else None,
            "shipping_address_hash": PgtypeText.from_dict(obj["shipping_address_hash"]) if obj.get("shipping_address_hash") is not None else None,
            "shipping_address_json": obj.get("shipping_address_json"),
            "shipping_amount": obj.get("shipping_amount"),
            "source_name": obj.get("source_name"),
            "status": obj.get("status"),
            "store_entity_id": PgtypeText.from_dict(obj["store_entity_id"]) if obj.get("store_entity_id") is not None else None,
            "subtotal_amount": obj.get("subtotal_amount"),
            "tax_amount": obj.get("tax_amount"),
            "total_amount": obj.get("total_amount")
        })
        return _obj


