# 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 Optional
from pydantic import BaseModel, Field, StrictInt, StrictStr, conint
from access_server_connector.models.access_mode import AccessMode
from access_server_connector.models.binding import Binding
from access_server_connector.models.resource_type import ResourceType

class PackageRuleIn(BaseModel):
    """
    PackageRuleIn
    """
    access_mode: Optional[AccessMode] = None
    unlock_delay_ms: Optional[conint(strict=True, ge=0)] = 0
    unlock_align_cron: Optional[StrictStr] = None
    access_duration_ms: Optional[conint(strict=True, gt=0)] = None
    starts_at: Optional[StrictInt] = None
    ends_at: Optional[StrictInt] = None
    window_cron: Optional[StrictStr] = None
    window_duration_ms: Optional[conint(strict=True, gt=0)] = None
    timezone: Optional[StrictStr] = None
    binding: Optional[Binding] = None
    resource_type: ResourceType = Field(...)
    resource_id: StrictInt = Field(...)
    expired_message: Optional[StrictStr] = None
    __properties = ["access_mode", "unlock_delay_ms", "unlock_align_cron", "access_duration_ms", "starts_at", "ends_at", "window_cron", "window_duration_ms", "timezone", "binding", "resource_type", "resource_id", "expired_message"]

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = PackageRuleIn.parse_obj({
            "access_mode": obj.get("access_mode"),
            "unlock_delay_ms": obj.get("unlock_delay_ms") if obj.get("unlock_delay_ms") is not None else 0,
            "unlock_align_cron": obj.get("unlock_align_cron"),
            "access_duration_ms": obj.get("access_duration_ms"),
            "starts_at": obj.get("starts_at"),
            "ends_at": obj.get("ends_at"),
            "window_cron": obj.get("window_cron"),
            "window_duration_ms": obj.get("window_duration_ms"),
            "timezone": obj.get("timezone"),
            "binding": obj.get("binding"),
            "resource_type": obj.get("resource_type"),
            "resource_id": obj.get("resource_id"),
            "expired_message": obj.get("expired_message")
        })
        return _obj


