# coding: utf-8

"""
    Canva Connect API

    API for building integrations with Canva via a REST api

    The version of the OpenAPI document: latest
    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
from canva_alpha_ti.models.approval_request_action import ApprovalRequestAction
from canva_alpha_ti.models.design_summary import DesignSummary
from canva_alpha_ti.models.group import Group
from canva_alpha_ti.models.team_user import TeamUser
from canva_alpha_ti.models.user import User
from typing import Optional, Set
from typing_extensions import Self

class DesignApprovalRequestedNotificationContent(BaseModel):
    """
    The notification content for when someone requests a user to [approve a design](https://www.canva.com/help/get-approval/).
    """ # noqa: E501
    type: StrictStr
    triggering_user: User
    initial_requesting_user: TeamUser
    receiving_team_user: TeamUser
    requested_groups: List[Group]
    design: DesignSummary
    approve_url: StrictStr = Field(description="A URL, which is scoped only to the user requested to review the design, that links to the design with the approval UI opened.")
    approval_request: ApprovalRequestAction
    __properties: ClassVar[List[str]] = ["type", "triggering_user", "initial_requesting_user", "receiving_team_user", "requested_groups", "design", "approve_url", "approval_request"]

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['design_approval_requested']):
            raise ValueError("must be one of enum values ('design_approval_requested')")
        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 DesignApprovalRequestedNotificationContent 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 triggering_user
        if self.triggering_user:
            _dict['triggering_user'] = self.triggering_user.to_dict()
        # override the default output from pydantic by calling `to_dict()` of initial_requesting_user
        if self.initial_requesting_user:
            _dict['initial_requesting_user'] = self.initial_requesting_user.to_dict()
        # override the default output from pydantic by calling `to_dict()` of receiving_team_user
        if self.receiving_team_user:
            _dict['receiving_team_user'] = self.receiving_team_user.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in requested_groups (list)
        _items = []
        if self.requested_groups:
            for _item_requested_groups in self.requested_groups:
                if _item_requested_groups:
                    _items.append(_item_requested_groups.to_dict())
            _dict['requested_groups'] = _items
        # override the default output from pydantic by calling `to_dict()` of design
        if self.design:
            _dict['design'] = self.design.to_dict()
        # override the default output from pydantic by calling `to_dict()` of approval_request
        if self.approval_request:
            _dict['approval_request'] = self.approval_request.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "type": obj.get("type"),
            "triggering_user": User.from_dict(obj["triggering_user"]) if obj.get("triggering_user") is not None else None,
            "initial_requesting_user": TeamUser.from_dict(obj["initial_requesting_user"]) if obj.get("initial_requesting_user") is not None else None,
            "receiving_team_user": TeamUser.from_dict(obj["receiving_team_user"]) if obj.get("receiving_team_user") is not None else None,
            "requested_groups": [Group.from_dict(_item) for _item in obj["requested_groups"]] if obj.get("requested_groups") is not None else None,
            "design": DesignSummary.from_dict(obj["design"]) if obj.get("design") is not None else None,
            "approve_url": obj.get("approve_url"),
            "approval_request": ApprovalRequestAction.from_dict(obj["approval_request"]) if obj.get("approval_request") is not None else None
        })
        return _obj


