# 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 pydantic import BaseModel, ConfigDict, Field, StrictInt
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from access_server_connector_v2.models.access_mode import AccessMode
from access_server_connector_v2.models.binding import Binding
from access_server_connector_v2.models.expiry_type import ExpiryType
from access_server_connector_v2.models.unlock_type import UnlockType
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class RuleBody(BaseModel):
    """
    RuleBody
    """ # noqa: E501
    access_mode: Optional[AccessMode] = None
    unlock_type: Optional[UnlockType] = None
    unlock_days: Optional[StrictInt] = None
    unlock_weekday: Optional[Annotated[int, Field(le=6, strict=True, ge=0)]] = None
    unlock_weekdays: Optional[List[StrictInt]] = None
    unlock_date: Optional[StrictInt] = None
    expiry_type: Optional[ExpiryType] = None
    expiry_days: Optional[StrictInt] = None
    expiry_date: Optional[StrictInt] = None
    binding: Optional[Binding] = None
    __properties: ClassVar[List[str]] = ["access_mode", "unlock_type", "unlock_days", "unlock_weekday", "unlock_weekdays", "unlock_date", "expiry_type", "expiry_days", "expiry_date", "binding"]

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=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"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of RuleBody 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,
        )
        # set to None if unlock_days (nullable) is None
        # and model_fields_set contains the field
        if self.unlock_days is None and "unlock_days" in self.model_fields_set:
            _dict['unlock_days'] = None

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "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


