# coding: utf-8

"""
    RobotnikAI API

    Documentation of API endpoints of RobotnikAI

    The version of the OpenAPI document: 1.0.0
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from robotnikai.models.api_key_distribution_enum import ApiKeyDistributionEnum
from robotnikai.models.hmac_algorithm_enum import HmacAlgorithmEnum
from robotnikai.models.integration_settings_hmac_key_format import IntegrationSettingsHmacKeyFormat
from robotnikai.models.integration_type import IntegrationType
from typing import Optional, Set
from typing_extensions import Self

class IntegrationSettings(BaseModel):
    """
    IntegrationSettings
    """ # noqa: E501
    integration_id: Annotated[str, Field(strict=True, max_length=100)]
    type: Optional[IntegrationType] = None
    connected_accounts: Optional[Any] = None
    account_fields: Optional[Any] = Field(default=None, description="Pola identyfikujące użytkownika")
    dependencies: Optional[Any] = Field(default=None, description="Zależności wymagane do działania integracji")
    scope: Optional[StrictStr] = None
    accept_header: Optional[Annotated[str, Field(strict=True, max_length=50)]] = None
    api_auth_header_name: Optional[Annotated[str, Field(strict=True, max_length=50)]] = None
    api_auth_header_key: Optional[Annotated[str, Field(strict=True, max_length=50)]] = None
    api_key_distribution: Optional[ApiKeyDistributionEnum] = None
    api_key_query_param_key: Optional[Annotated[str, Field(strict=True, max_length=50)]] = None
    api_key_body_param_key: Optional[Annotated[str, Field(strict=True, max_length=50)]] = None
    api_base_url: Optional[Annotated[str, Field(strict=True, max_length=200)]] = None
    api_schema: Optional[Any] = None
    authorize_url: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    access_token_url: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    identity_url: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    oauth_basic_auth: Optional[StrictBool] = None
    oauth_pkce_enabled: Optional[StrictBool] = None
    variables: Optional[Any] = None
    openapi_json_scheme_url: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    is_sandbox: Optional[StrictBool] = None
    hmac_algorithm: Optional[HmacAlgorithmEnum] = None
    hmac_fields: Optional[Any] = Field(default=None, description="Fields to include in HMAC signature")
    hmac_separator: Optional[Annotated[str, Field(strict=True, max_length=20)]] = None
    hmac_header_placeholder: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    hmac_custom_signature_field: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    hmac_key_format: Optional[IntegrationSettingsHmacKeyFormat] = None
    status_check_url: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    __properties: ClassVar[List[str]] = ["integration_id", "type", "connected_accounts", "account_fields", "dependencies", "scope", "accept_header", "api_auth_header_name", "api_auth_header_key", "api_key_distribution", "api_key_query_param_key", "api_key_body_param_key", "api_base_url", "api_schema", "authorize_url", "access_token_url", "identity_url", "oauth_basic_auth", "oauth_pkce_enabled", "variables", "openapi_json_scheme_url", "is_sandbox", "hmac_algorithm", "hmac_fields", "hmac_separator", "hmac_header_placeholder", "hmac_custom_signature_field", "hmac_key_format", "status_check_url"]

    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 IntegrationSettings 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "type",
            "connected_accounts",
            "variables",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of type
        if self.type:
            _dict['type'] = self.type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of hmac_key_format
        if self.hmac_key_format:
            _dict['hmac_key_format'] = self.hmac_key_format.to_dict()
        # set to None if connected_accounts (nullable) is None
        # and model_fields_set contains the field
        if self.connected_accounts is None and "connected_accounts" in self.model_fields_set:
            _dict['connected_accounts'] = None

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "integration_id": obj.get("integration_id"),
            "type": IntegrationType.from_dict(obj["type"]) if obj.get("type") is not None else None,
            "connected_accounts": obj.get("connected_accounts"),
            "account_fields": obj.get("account_fields"),
            "dependencies": obj.get("dependencies"),
            "scope": obj.get("scope"),
            "accept_header": obj.get("accept_header"),
            "api_auth_header_name": obj.get("api_auth_header_name"),
            "api_auth_header_key": obj.get("api_auth_header_key"),
            "api_key_distribution": obj.get("api_key_distribution"),
            "api_key_query_param_key": obj.get("api_key_query_param_key"),
            "api_key_body_param_key": obj.get("api_key_body_param_key"),
            "api_base_url": obj.get("api_base_url"),
            "api_schema": obj.get("api_schema"),
            "authorize_url": obj.get("authorize_url"),
            "access_token_url": obj.get("access_token_url"),
            "identity_url": obj.get("identity_url"),
            "oauth_basic_auth": obj.get("oauth_basic_auth"),
            "oauth_pkce_enabled": obj.get("oauth_pkce_enabled"),
            "variables": obj.get("variables"),
            "openapi_json_scheme_url": obj.get("openapi_json_scheme_url"),
            "is_sandbox": obj.get("is_sandbox"),
            "hmac_algorithm": obj.get("hmac_algorithm"),
            "hmac_fields": obj.get("hmac_fields"),
            "hmac_separator": obj.get("hmac_separator"),
            "hmac_header_placeholder": obj.get("hmac_header_placeholder"),
            "hmac_custom_signature_field": obj.get("hmac_custom_signature_field"),
            "hmac_key_format": IntegrationSettingsHmacKeyFormat.from_dict(obj["hmac_key_format"]) if obj.get("hmac_key_format") is not None else None,
            "status_check_url": obj.get("status_check_url")
        })
        return _obj


