# coding: utf-8

"""
    Rapidata Asset API

    The API for the Rapidata Asset service

    The version of the OpenAPI document: v1
    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
from typing import Any, ClassVar, Dict, List, Optional
from rapidata.api_client.models.json_web_key_set import JsonWebKeySet
from typing import Optional, Set
from typing_extensions import Self

class DynamicClientRegistrationRequest(BaseModel):
    """
    The request body for dynamic client registration.
    """ # noqa: E501
    redirect_uris: Optional[List[StrictStr]] = None
    grant_types: Optional[List[StrictStr]] = None
    response_types: Optional[List[StrictStr]] = None
    client_id: Optional[StrictStr] = None
    client_name: Optional[StrictStr] = None
    client_uri: Optional[StrictStr] = None
    logo_uri: Optional[StrictStr] = None
    scope: Optional[StrictStr] = Field(default=None, description="String containing a space-separated list of scope values  that the client can use when requesting access tokens.")
    contacts: Optional[List[StrictStr]] = None
    tos_uri: Optional[StrictStr] = None
    policy_uri: Optional[StrictStr] = None
    jwks_uri: Optional[StrictStr] = None
    jwks: Optional[JsonWebKeySet] = Field(default=None, description="Client's JSON Web Key Set [RFC7517] document value, which contains the client's public keys.")
    __properties: ClassVar[List[str]] = ["redirect_uris", "grant_types", "response_types", "client_id", "client_name", "client_uri", "logo_uri", "scope", "contacts", "tos_uri", "policy_uri", "jwks_uri", "jwks"]

    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 DynamicClientRegistrationRequest 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 jwks
        if self.jwks:
            _dict['jwks'] = self.jwks.to_dict()
        # set to None if client_id (nullable) is None
        # and model_fields_set contains the field
        if self.client_id is None and "client_id" in self.model_fields_set:
            _dict['client_id'] = None

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "redirect_uris": obj.get("redirect_uris"),
            "grant_types": obj.get("grant_types"),
            "response_types": obj.get("response_types"),
            "client_id": obj.get("client_id"),
            "client_name": obj.get("client_name"),
            "client_uri": obj.get("client_uri"),
            "logo_uri": obj.get("logo_uri"),
            "scope": obj.get("scope"),
            "contacts": obj.get("contacts"),
            "tos_uri": obj.get("tos_uri"),
            "policy_uri": obj.get("policy_uri"),
            "jwks_uri": obj.get("jwks_uri"),
            "jwks": JsonWebKeySet.from_dict(obj["jwks"]) if obj.get("jwks") is not None else None
        })
        return _obj


