# coding: utf-8

"""
    Instana REST API documentation

    Documentation for INSTANA REST API

    The version of the OpenAPI document: 1.309.1268
    Contact: support@instana.com
    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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class AccessRule(BaseModel):
    """
    AccessRule
    """ # noqa: E501
    access_type: StrictStr = Field(description="Specifies the type of access permitted.   `READ`: Only viewing Application Perspective is allowed.   `READ_WRITE`: Both viewing and modifying Application Perspective are permitted.   ", alias="accessType")
    related_id: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=64)]] = Field(default=None, description="An identifier that connects the access rule to a specific entity. For example, if the `relationType` is `USER`, the corresponding `relatedId` would be a user id.   **Note**: when `relationType` is `GLOBAL`, `relatedId` is `null`. ", alias="relatedId")
    relation_type: StrictStr = Field(description="Defines the type of relationship or subject to which the access rule applies.   `USER`: Access is granted to an individual user.   `API_TOKEN`: Access is granted to a specific API token.   `ROLE`: Access is granted based on a user role, applying to any user with that role.   `TEAM`: Access is granted to a team, likely applying to all team members.   `GLOBAL`: Access is granted to every user or service. ", alias="relationType")
    __properties: ClassVar[List[str]] = ["accessType", "relatedId", "relationType"]

    @field_validator('access_type')
    def access_type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['READ', 'READ_WRITE']):
            raise ValueError("must be one of enum values ('READ', 'READ_WRITE')")
        return value

    @field_validator('relation_type')
    def relation_type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['USER', 'API_TOKEN', 'ROLE', 'TEAM', 'GLOBAL']):
            raise ValueError("must be one of enum values ('USER', 'API_TOKEN', 'ROLE', 'TEAM', 'GLOBAL')")
        return value

    model_config = ConfigDict(
        populate_by_name=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"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of AccessRule 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "accessType": obj.get("accessType"),
            "relatedId": obj.get("relatedId"),
            "relationType": obj.get("relationType")
        })
        return _obj


