# 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, StrictBool, StrictInt
from access_server_connector.models.reason_kind import ReasonKind
from access_server_connector.models.reason_status import ReasonStatus

class MemberOwnershipOut(BaseModel):
    """
    A member's hold on a package — for the 'who has access to this package' roster.  # noqa: E501
    """
    member_id: StrictInt = Field(...)
    reason_id: StrictInt = Field(...)
    access_package_id: StrictInt = Field(...)
    kind: ReasonKind = Field(...)
    status: ReasonStatus = Field(...)
    granted_at: StrictInt = Field(...)
    is_test: StrictBool = Field(...)
    period_end: Optional[StrictInt] = Field(...)
    grace_until: Optional[StrictInt] = Field(...)
    __properties = ["member_id", "reason_id", "access_package_id", "kind", "status", "granted_at", "is_test", "period_end", "grace_until"]

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

        return _dict

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

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

        _obj = MemberOwnershipOut.parse_obj({
            "member_id": obj.get("member_id"),
            "reason_id": obj.get("reason_id"),
            "access_package_id": obj.get("access_package_id"),
            "kind": obj.get("kind"),
            "status": obj.get("status"),
            "granted_at": obj.get("granted_at"),
            "is_test": obj.get("is_test"),
            "period_end": obj.get("period_end"),
            "grace_until": obj.get("grace_until")
        })
        return _obj


