# coding: utf-8

"""
    authentik

    Making authentication simple.

    The version of the OpenAPI document: 2024.2.2
    Contact: hello@goauthentik.io
    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 datetime import datetime
from typing import Any, Dict, Optional
from pydantic import BaseModel, Field, StrictBool, StrictStr, constr, validator
from authentik_client.models.flow import Flow
from authentik_client.models.group_member import GroupMember

class Invitation(BaseModel):
    """
    Invitation Serializer  # noqa: E501
    """
    pk: StrictStr = Field(...)
    name: constr(strict=True, max_length=50) = Field(...)
    expires: Optional[datetime] = None
    fixed_data: Optional[Dict[str, Any]] = None
    created_by: GroupMember = Field(...)
    single_use: Optional[StrictBool] = Field(None, description="When enabled, the invitation will be deleted after usage.")
    flow: Optional[StrictStr] = Field(None, description="When set, only the configured flow can use this invitation.")
    flow_obj: Flow = Field(...)
    __properties = ["pk", "name", "expires", "fixed_data", "created_by", "single_use", "flow", "flow_obj"]

    @validator('name')
    def name_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^[-a-zA-Z0-9_]+$", value):
            raise ValueError(r"must validate the regular expression /^[-a-zA-Z0-9_]+$/")
        return value

    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) -> Invitation:
        """Create an instance of Invitation 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={
                            "pk",
                            "created_by",
                            "flow_obj",
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of created_by
        if self.created_by:
            _dict['created_by'] = self.created_by.to_dict()
        # override the default output from pydantic by calling `to_dict()` of flow_obj
        if self.flow_obj:
            _dict['flow_obj'] = self.flow_obj.to_dict()
        # set to None if flow (nullable) is None
        # and __fields_set__ contains the field
        if self.flow is None and "flow" in self.__fields_set__:
            _dict['flow'] = None

        return _dict

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

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

        _obj = Invitation.parse_obj({
            "pk": obj.get("pk"),
            "name": obj.get("name"),
            "expires": obj.get("expires"),
            "fixed_data": obj.get("fixed_data"),
            "created_by": GroupMember.from_dict(obj.get("created_by")) if obj.get("created_by") is not None else None,
            "single_use": obj.get("single_use"),
            "flow": obj.get("flow"),
            "flow_obj": Flow.from_dict(obj.get("flow_obj")) if obj.get("flow_obj") is not None else None
        })
        return _obj


