# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.api_tag import ApiTag
from typing import Optional, Set
from typing_extensions import Self

class SyntheticCredential(BaseModel):
    """
    SyntheticCredential
    """ # noqa: E501
    application_labels: Optional[List[StrictStr]] = Field(default=None, alias="applicationLabels")
    applications: Optional[List[StrictStr]] = None
    created_at: Optional[StrictInt] = Field(default=None, alias="createdAt")
    created_by: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=128)]] = Field(default=None, alias="createdBy")
    credential_name: Annotated[str, Field(min_length=1, strict=True, max_length=128)] = Field(alias="credentialName")
    credential_value: StrictStr = Field(alias="credentialValue")
    mobile_app_labels: Optional[List[StrictStr]] = Field(default=None, alias="mobileAppLabels")
    mobile_apps: Optional[List[StrictStr]] = Field(default=None, alias="mobileApps")
    modified_at: Optional[StrictInt] = Field(default=None, alias="modifiedAt")
    modified_by: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=128)]] = Field(default=None, alias="modifiedBy")
    rbac_tags: Optional[List[ApiTag]] = Field(default=None, alias="rbacTags")
    website_labels: Optional[List[StrictStr]] = Field(default=None, alias="websiteLabels")
    websites: Optional[List[StrictStr]] = None
    __properties: ClassVar[List[str]] = ["applicationLabels", "applications", "createdAt", "createdBy", "credentialName", "credentialValue", "mobileAppLabels", "mobileApps", "modifiedAt", "modifiedBy", "rbacTags", "websiteLabels", "websites"]

    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 SyntheticCredential 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "application_labels",
            "created_at",
            "mobile_app_labels",
            "modified_at",
            "website_labels",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in rbac_tags (list)
        _items = []
        if self.rbac_tags:
            for _item_rbac_tags in self.rbac_tags:
                if _item_rbac_tags:
                    _items.append(_item_rbac_tags.to_dict())
            _dict['rbacTags'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "applicationLabels": obj.get("applicationLabels"),
            "applications": obj.get("applications"),
            "createdAt": obj.get("createdAt"),
            "createdBy": obj.get("createdBy"),
            "credentialName": obj.get("credentialName"),
            "credentialValue": obj.get("credentialValue"),
            "mobileAppLabels": obj.get("mobileAppLabels"),
            "mobileApps": obj.get("mobileApps"),
            "modifiedAt": obj.get("modifiedAt"),
            "modifiedBy": obj.get("modifiedBy"),
            "rbacTags": [ApiTag.from_dict(_item) for _item in obj["rbacTags"]] if obj.get("rbacTags") is not None else None,
            "websiteLabels": obj.get("websiteLabels"),
            "websites": obj.get("websites")
        })
        return _obj


