# 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, conlist
from access_server_connector.models.access_mode import AccessMode
from access_server_connector.models.binding import Binding
from access_server_connector.models.expiry_type import ExpiryType
from access_server_connector.models.unlock_type import UnlockType

class RuleBodyOut(BaseModel):
    """
    An override's optional rule body (all fields nullable — sparse).  # noqa: E501
    """
    access_mode: Optional[AccessMode] = Field(...)
    unlock_type: Optional[UnlockType] = Field(...)
    unlock_days: Optional[StrictInt] = Field(...)
    unlock_weekday: Optional[StrictInt] = Field(...)
    unlock_weekdays: Optional[conlist(StrictInt)] = Field(...)
    unlock_date: Optional[StrictInt] = Field(...)
    expiry_type: Optional[ExpiryType] = Field(...)
    expiry_days: Optional[StrictInt] = Field(...)
    expiry_date: Optional[StrictInt] = Field(...)
    binding: Optional[Binding] = Field(...)
    __properties = ["access_mode", "unlock_type", "unlock_days", "unlock_weekday", "unlock_weekdays", "unlock_date", "expiry_type", "expiry_days", "expiry_date", "binding"]

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = RuleBodyOut.parse_obj({
            "access_mode": obj.get("access_mode"),
            "unlock_type": obj.get("unlock_type"),
            "unlock_days": obj.get("unlock_days"),
            "unlock_weekday": obj.get("unlock_weekday"),
            "unlock_weekdays": obj.get("unlock_weekdays"),
            "unlock_date": obj.get("unlock_date"),
            "expiry_type": obj.get("expiry_type"),
            "expiry_days": obj.get("expiry_days"),
            "expiry_date": obj.get("expiry_date"),
            "binding": obj.get("binding")
        })
        return _obj


