# coding: utf-8

"""
    Mentortools Access Server

    Mentortools service for Access Packages with lazy access resolution

    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 List, Optional
from pydantic import BaseModel, Field, StrictInt, StrictStr, conlist
from access_server_connector.models.event_order import EventOrder
from access_server_connector.models.event_product import EventProduct
from access_server_connector.models.event_subscription import EventSubscription
from access_server_connector.models.reason_kind import ReasonKind
from access_server_connector.models.reason_status import ReasonStatus

class AccessOrderEvent(BaseModel):
    """
    AccessOrderEvent
    """
    event_id: StrictStr = Field(...)
    occurred_at: StrictInt = Field(...)
    portal_id: StrictInt = Field(...)
    member_id: StrictInt = Field(...)
    reason_kind: Optional[ReasonKind] = None
    product: Optional[EventProduct] = None
    access_package_ids: Optional[conlist(StrictInt)] = None
    order: Optional[EventOrder] = None
    status: ReasonStatus = Field(...)
    status_reason: Optional[StrictStr] = None
    subscription: Optional[EventSubscription] = None
    __properties = ["event_id", "occurred_at", "portal_id", "member_id", "reason_kind", "product", "access_package_ids", "order", "status", "status_reason", "subscription"]

    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) -> AccessOrderEvent:
        """Create an instance of AccessOrderEvent 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 product
        if self.product:
            _dict['product'] = self.product.to_dict()
        # override the default output from pydantic by calling `to_dict()` of order
        if self.order:
            _dict['order'] = self.order.to_dict()
        # override the default output from pydantic by calling `to_dict()` of subscription
        if self.subscription:
            _dict['subscription'] = self.subscription.to_dict()
        # set to None if product (nullable) is None
        # and __fields_set__ contains the field
        if self.product is None and "product" in self.__fields_set__:
            _dict['product'] = None

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

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

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

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

        return _dict

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

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

        _obj = AccessOrderEvent.parse_obj({
            "event_id": obj.get("event_id"),
            "occurred_at": obj.get("occurred_at"),
            "portal_id": obj.get("portal_id"),
            "member_id": obj.get("member_id"),
            "reason_kind": obj.get("reason_kind"),
            "product": EventProduct.from_dict(obj.get("product")) if obj.get("product") is not None else None,
            "access_package_ids": obj.get("access_package_ids"),
            "order": EventOrder.from_dict(obj.get("order")) if obj.get("order") is not None else None,
            "status": obj.get("status"),
            "status_reason": obj.get("status_reason"),
            "subscription": EventSubscription.from_dict(obj.get("subscription")) if obj.get("subscription") is not None else None
        })
        return _obj


