# coding: utf-8

"""
    Mentortools Marketplace Server

    Mentortools service for ingesting payment-provider webhooks into normalized order events

    The version of the OpenAPI document: 0.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 typing import Optional
from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr
from marketplace_server_connector.models.import_buyer_in import ImportBuyerIn
from marketplace_server_connector.models.payment_type import PaymentType
from marketplace_server_connector.models.provider import Provider

class ImportOrderIn(BaseModel):
    """
    ImportOrderIn
    """
    provider: Provider = Field(...)
    buyer: ImportBuyerIn = Field(...)
    external_product_id: StrictStr = Field(...)
    product_title: Optional[StrictStr] = None
    payment_type: Optional[PaymentType] = None
    occurred_at: StrictInt = Field(...)
    external_order_id: Optional[StrictStr] = None
    external_subscription_id: Optional[StrictStr] = None
    period_end: Optional[StrictInt] = None
    amount: Optional[StrictInt] = None
    is_test: Optional[StrictBool] = False
    __properties = ["provider", "buyer", "external_product_id", "product_title", "payment_type", "occurred_at", "external_order_id", "external_subscription_id", "period_end", "amount", "is_test"]

    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) -> ImportOrderIn:
        """Create an instance of ImportOrderIn 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 buyer
        if self.buyer:
            _dict['buyer'] = self.buyer.to_dict()
        # set to None if product_title (nullable) is None
        # and __fields_set__ contains the field
        if self.product_title is None and "product_title" in self.__fields_set__:
            _dict['product_title'] = None

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

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

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

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

        return _dict

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

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

        _obj = ImportOrderIn.parse_obj({
            "provider": obj.get("provider"),
            "buyer": ImportBuyerIn.from_dict(obj.get("buyer")) if obj.get("buyer") is not None else None,
            "external_product_id": obj.get("external_product_id"),
            "product_title": obj.get("product_title"),
            "payment_type": obj.get("payment_type"),
            "occurred_at": obj.get("occurred_at"),
            "external_order_id": obj.get("external_order_id"),
            "external_subscription_id": obj.get("external_subscription_id"),
            "period_end": obj.get("period_end"),
            "amount": obj.get("amount"),
            "is_test": obj.get("is_test") if obj.get("is_test") is not None else False
        })
        return _obj


