# coding: utf-8

"""
    Dropbox Sign API

    Dropbox Sign v3 API

    The version of the OpenAPI document: 3.0.0
    Contact: apisupport@hellosign.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, StrictBytes, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from dropbox_sign.models.sub_o_auth import SubOAuth
from dropbox_sign.models.sub_options import SubOptions
from dropbox_sign.models.sub_white_labeling_options import SubWhiteLabelingOptions
from typing import Optional, Set, Tuple
from typing_extensions import Self
import io
from pydantic import StrictBool
from typing import Union


class ApiAppCreateRequest(BaseModel):
    """
    ApiAppCreateRequest
    """  # noqa: E501

    domains: Annotated[List[StrictStr], Field(min_length=1, max_length=2)] = Field(
        description="The domain names the ApiApp will be associated with."
    )
    name: StrictStr = Field(description="The name you want to assign to the ApiApp.")
    callback_url: Optional[StrictStr] = Field(
        default=None,
        description="The URL at which the ApiApp should receive event callbacks.",
    )
    custom_logo_file: Optional[Union[StrictBytes, StrictStr, io.IOBase]] = Field(
        default=None,
        description="An image file to use as a custom logo in embedded contexts. (Only applies to some API plans)",
    )
    oauth: Optional[SubOAuth] = None
    options: Optional[SubOptions] = None
    white_labeling_options: Optional[SubWhiteLabelingOptions] = None
    __properties: ClassVar[List[str]] = [
        "domains",
        "name",
        "callback_url",
        "custom_logo_file",
        "oauth",
        "options",
        "white_labeling_options",
    ]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
        arbitrary_types_allowed=True,
    )

    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())

    def to_json_form_params(
        self, excluded_fields: Set[str] = None
    ) -> List[Tuple[str, str]]:
        data: List[Tuple[str, str]] = []

        for key, value in self.to_dict(excluded_fields).items():
            if isinstance(value, (int, str, bool)):
                data.append((key, value))
            else:
                data.append((key, json.dumps(value, ensure_ascii=False)))

        return data

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of ApiAppCreateRequest from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self, excluded_fields: Set[str] = None) -> 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.
        """

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of oauth
        if self.oauth:
            _dict["oauth"] = self.oauth.to_dict()
        # override the default output from pydantic by calling `to_dict()` of options
        if self.options:
            _dict["options"] = self.options.to_dict()
        # override the default output from pydantic by calling `to_dict()` of white_labeling_options
        if self.white_labeling_options:
            _dict["white_labeling_options"] = self.white_labeling_options.to_dict()
        return _dict

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

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

        _obj = cls.model_validate(
            {
                "domains": obj.get("domains"),
                "name": obj.get("name"),
                "callback_url": obj.get("callback_url"),
                "custom_logo_file": obj.get("custom_logo_file"),
                "oauth": (
                    SubOAuth.from_dict(obj["oauth"])
                    if obj.get("oauth") is not None
                    else None
                ),
                "options": (
                    SubOptions.from_dict(obj["options"])
                    if obj.get("options") is not None
                    else None
                ),
                "white_labeling_options": (
                    SubWhiteLabelingOptions.from_dict(obj["white_labeling_options"])
                    if obj.get("white_labeling_options") is not None
                    else None
                ),
            }
        )
        return _obj

    @classmethod
    def init(cls, data: Any) -> Self:
        """
        Attempt to instantiate and hydrate a new instance of this class
        """
        if isinstance(data, str):
            data = json.loads(data)

        return cls.from_dict(data)

    @classmethod
    def openapi_types(cls) -> Dict[str, str]:
        return {
            "domains": "(List[str],)",
            "name": "(str,)",
            "callback_url": "(str,)",
            "custom_logo_file": "(io.IOBase,)",
            "oauth": "(SubOAuth,)",
            "options": "(SubOptions,)",
            "white_labeling_options": "(SubWhiteLabelingOptions,)",
        }

    @classmethod
    def openapi_type_is_array(cls, property_name: str) -> bool:
        return property_name in [
            "domains",
        ]
