# coding: utf-8

"""
    Pinterest REST API

    Pinterest's REST API

    The version of the OpenAPI document: 5.23.0
    Contact: blah+oapicf@cliffano.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, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.business_access_user_summary import BusinessAccessUserSummary
from pinterestsdk.models.business_member_assets_summary import BusinessMemberAssetsSummary
from typing import Optional, Set
from typing_extensions import Self

class UserBusinessRoleBinding(BaseModel):
    """
    UserBusinessRoleBinding
    """ # noqa: E501
    assets_summary: Optional[BusinessMemberAssetsSummary] = None
    business_roles: Optional[List[StrictStr]] = Field(default=None, description="The access level a user has on the business. This can be EMPLOYEE, BIZ_ADMIN, or PARTNER.")
    created_by_business: Optional[BusinessAccessUserSummary] = Field(default=None, description="Metadata for the business that created the business relationship.")
    created_by_user: Optional[BusinessAccessUserSummary] = Field(default=None, description="Metadata for the user that created the business relationship.")
    created_time: Optional[StrictInt] = Field(default=None, description="The time the business relationship was created. Returned in milliseconds.")
    id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Unique identifier of the business member/business partner/employer.")
    is_shared_partner: Optional[StrictBool] = Field(default=None, description="This field is only relevant when business_role=\"PARTNER\". <br>If is_shared_partner=FALSE, the partner can access your business assets. If assets_summary is not empty, the assets listed are your business assets the partner has access to. <br>If is_shared_partner=TRUE, you can access the partner's business asset. If assets_summary is not empty, the assets listed are the partner's business assets you have access to.")
    user: Optional[BusinessAccessUserSummary] = Field(default=None, description="Metadata for the business member/business partner/employer.")
    __properties: ClassVar[List[str]] = ["assets_summary", "business_roles", "created_by_business", "created_by_user", "created_time", "id", "is_shared_partner", "user"]

    @field_validator('id')
    def id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+$/")
        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 UserBusinessRoleBinding 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,
        )
        # override the default output from pydantic by calling `to_dict()` of assets_summary
        if self.assets_summary:
            _dict['assets_summary'] = self.assets_summary.to_dict()
        # override the default output from pydantic by calling `to_dict()` of created_by_business
        if self.created_by_business:
            _dict['created_by_business'] = self.created_by_business.to_dict()
        # override the default output from pydantic by calling `to_dict()` of created_by_user
        if self.created_by_user:
            _dict['created_by_user'] = self.created_by_user.to_dict()
        # override the default output from pydantic by calling `to_dict()` of user
        if self.user:
            _dict['user'] = self.user.to_dict()
        # set to None if assets_summary (nullable) is None
        # and model_fields_set contains the field
        if self.assets_summary is None and "assets_summary" in self.model_fields_set:
            _dict['assets_summary'] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "assets_summary": BusinessMemberAssetsSummary.from_dict(obj["assets_summary"]) if obj.get("assets_summary") is not None else None,
            "business_roles": obj.get("business_roles"),
            "created_by_business": BusinessAccessUserSummary.from_dict(obj["created_by_business"]) if obj.get("created_by_business") is not None else None,
            "created_by_user": BusinessAccessUserSummary.from_dict(obj["created_by_user"]) if obj.get("created_by_user") is not None else None,
            "created_time": obj.get("created_time"),
            "id": obj.get("id"),
            "is_shared_partner": obj.get("is_shared_partner"),
            "user": BusinessAccessUserSummary.from_dict(obj["user"]) if obj.get("user") is not None else None
        })
        return _obj


