# coding: utf-8

"""
    Logto API references

    API references for Logto services. To learn more about how to interact with Logto APIs, see [Interact with Management API](https://docs.logto.io/docs/recipes/interact-with-management-api/).

    The version of the OpenAPI document: Cloud
    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, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from py_logto.models.api_connectors_get200_response_inner_form_items_inner import ApiConnectorsGet200ResponseInnerFormItemsInner
from py_logto.models.api_connectors_get200_response_inner_metadata import ApiConnectorsGet200ResponseInnerMetadata
from typing import Optional, Set
from typing_extensions import Self

class ApiConnectorsGet200ResponseInner(BaseModel):
    """
    ApiConnectorsGet200ResponseInner
    """ # noqa: E501
    id: StrictStr
    sync_profile: StrictBool = Field(alias="syncProfile")
    config: Dict[str, Any] = Field(description="arbitrary")
    metadata: ApiConnectorsGet200ResponseInnerMetadata
    connector_id: Annotated[str, Field(min_length=1, strict=True, max_length=128)] = Field(alias="connectorId")
    target: StrictStr
    name: Dict[str, Any] = Field(description="Validator function")
    description: Dict[str, Any] = Field(description="Validator function")
    logo: StrictStr
    logo_dark: Optional[StrictStr] = Field(alias="logoDark")
    readme: StrictStr
    config_template: Optional[StrictStr] = Field(default=None, alias="configTemplate")
    form_items: Optional[List[ApiConnectorsGet200ResponseInnerFormItemsInner]] = Field(default=None, alias="formItems")
    platform: Optional[StrictStr]
    is_standard: Optional[StrictBool] = Field(default=None, alias="isStandard")
    type: StrictStr
    is_demo: Optional[StrictBool] = Field(default=None, alias="isDemo")
    extra_info: Optional[Dict[str, Any]] = Field(default=None, alias="extraInfo")
    usage: Optional[Union[StrictFloat, StrictInt]] = None
    __properties: ClassVar[List[str]] = ["id", "syncProfile", "config", "metadata", "connectorId", "target", "name", "description", "logo", "logoDark", "readme", "configTemplate", "formItems", "platform", "isStandard", "type", "isDemo", "extraInfo", "usage"]

    @field_validator('platform')
    def platform_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['Native', 'Universal', 'Web']):
            raise ValueError("must be one of enum values ('Native', 'Universal', 'Web')")
        return value

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['Email', 'Sms', 'Social']):
            raise ValueError("must be one of enum values ('Email', 'Sms', 'Social')")
        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 ApiConnectorsGet200ResponseInner 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 metadata
        if self.metadata:
            _dict['metadata'] = self.metadata.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in form_items (list)
        _items = []
        if self.form_items:
            for _item in self.form_items:
                if _item:
                    _items.append(_item.to_dict())
            _dict['formItems'] = _items
        # set to None if logo_dark (nullable) is None
        # and model_fields_set contains the field
        if self.logo_dark is None and "logo_dark" in self.model_fields_set:
            _dict['logoDark'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "syncProfile": obj.get("syncProfile"),
            "config": obj.get("config"),
            "metadata": ApiConnectorsGet200ResponseInnerMetadata.from_dict(obj["metadata"]) if obj.get("metadata") is not None else None,
            "connectorId": obj.get("connectorId"),
            "target": obj.get("target"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "logo": obj.get("logo"),
            "logoDark": obj.get("logoDark"),
            "readme": obj.get("readme"),
            "configTemplate": obj.get("configTemplate"),
            "formItems": [ApiConnectorsGet200ResponseInnerFormItemsInner.from_dict(_item) for _item in obj["formItems"]] if obj.get("formItems") is not None else None,
            "platform": obj.get("platform"),
            "isStandard": obj.get("isStandard"),
            "type": obj.get("type"),
            "isDemo": obj.get("isDemo"),
            "extraInfo": obj.get("extraInfo"),
            "usage": obj.get("usage")
        })
        return _obj


