# coding: utf-8

"""
    Automio API

    Documentation of API endpoints of Automio for SDK

    The version of the OpenAPI document: 0.1.2
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from automio.models.api_key_distribution_enum import ApiKeyDistributionEnum
from automio.models.hmac_algorithm_enum import HmacAlgorithmEnum
from automio.models.hmac_key_format_enum import HmacKeyFormatEnum
from automio.models.integration_category import IntegrationCategory
from automio.models.integration_type import IntegrationType
from typing import Optional, Set
from typing_extensions import Self

class Integration(BaseModel):
    """
    Integration
    """ # noqa: E501
    id: Optional[StrictInt] = None
    integration_id: Annotated[str, Field(strict=True, max_length=100)]
    type: Optional[IntegrationType] = None
    name: Annotated[str, Field(strict=True, max_length=150)]
    tags: Optional[List[StrictStr]] = None
    categories: Optional[List[IntegrationCategory]] = None
    version: Annotated[str, Field(strict=True, max_length=10)]
    icon: Optional[StrictStr] = None
    description: Optional[StrictStr] = None
    website_url: Optional[Annotated[str, Field(strict=True, max_length=200)]] = None
    account_fields: Optional[Any] = None
    dependencies: Optional[Any] = None
    configuration_form: Optional[Any] = None
    activated: Optional[StrictBool] = None
    owner: Optional[StrictInt] = None
    connected_accounts: Optional[Any] = None
    api_base_url: Optional[Annotated[str, Field(strict=True, max_length=200)]] = None
    account: Optional[Any] = None
    openapi_json_scheme_url: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    api_docs_url: Optional[Annotated[str, Field(strict=True, max_length=200)]] = None
    countries: Optional[List[Annotated[str, Field(strict=True, max_length=2)]]] = None
    is_global: Optional[StrictBool] = Field(default=None, description="Is the integration available globally? If true, countries field will be ignored.")
    is_sandbox: Optional[StrictBool] = False
    api_schema: Optional[StrictStr] = None
    is_official: Optional[StrictBool] = None
    client_id: Optional[Annotated[str, Field(strict=True, max_length=200)]] = None
    secret: Optional[Annotated[str, Field(strict=True, max_length=200)]] = None
    access_token_url: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    authorize_url: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    identity_url: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    scope: Optional[StrictStr] = ''
    oauth_basic_auth: Optional[StrictBool] = False
    oauth_pkce_enabled: Optional[StrictBool] = False
    accept_header: Optional[Annotated[str, Field(strict=True, max_length=50)]] = None
    api_key: Optional[Annotated[str, Field(strict=True, max_length=200)]] = 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_auth_header_name: Optional[StrictStr] = None
    api_auth_header_key: Optional[Annotated[str, Field(strict=True, max_length=50)]] = None
    hmac_algorithm: Optional[HmacAlgorithmEnum] = None
    hmac_fields: Optional[List[Annotated[str, Field(strict=True, max_length=50)]]] = None
    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[HmacKeyFormatEnum] = None
    status_check_url: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    wsdl_document_url: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    wsdl_auth_method: Optional[Annotated[str, Field(strict=True, max_length=20)]] = None
    wsdl_custom_auth: Optional[Annotated[str, Field(strict=True, max_length=500)]] = None
    extra_headers: Optional[Any] = None
    __properties: ClassVar[List[str]] = ["id", "integration_id", "type", "name", "tags", "categories", "version", "icon", "description", "website_url", "account_fields", "dependencies", "configuration_form", "activated", "owner", "connected_accounts", "api_base_url", "account", "openapi_json_scheme_url", "api_docs_url", "countries", "is_global", "is_sandbox", "api_schema", "is_official", "client_id", "secret", "access_token_url", "authorize_url", "identity_url", "scope", "oauth_basic_auth", "oauth_pkce_enabled", "accept_header", "api_key", "api_key_distribution", "api_key_query_param_key", "api_key_body_param_key", "api_auth_header_name", "api_auth_header_key", "hmac_algorithm", "hmac_fields", "hmac_separator", "hmac_header_placeholder", "hmac_custom_signature_field", "hmac_key_format", "status_check_url", "wsdl_document_url", "wsdl_auth_method", "wsdl_custom_auth", "extra_headers"]

    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 Integration 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "id",
            "type",
            "categories",
            "activated",
            "owner",
            "connected_accounts",
            "account",
            "is_official",
        ])

        _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 each item in categories (list)
        _items = []
        if self.categories:
            for _item_categories in self.categories:
                if _item_categories:
                    _items.append(_item_categories.to_dict())
            _dict['categories'] = _items
        # set to None if tags (nullable) is None
        # and model_fields_set contains the field
        if self.tags is None and "tags" in self.model_fields_set:
            _dict['tags'] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Integration 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"),
            "integration_id": obj.get("integration_id"),
            "type": IntegrationType.from_dict(obj["type"]) if obj.get("type") is not None else None,
            "name": obj.get("name"),
            "tags": obj.get("tags"),
            "categories": [IntegrationCategory.from_dict(_item) for _item in obj["categories"]] if obj.get("categories") is not None else None,
            "version": obj.get("version"),
            "icon": obj.get("icon"),
            "description": obj.get("description"),
            "website_url": obj.get("website_url"),
            "account_fields": obj.get("account_fields"),
            "dependencies": obj.get("dependencies"),
            "configuration_form": obj.get("configuration_form"),
            "activated": obj.get("activated"),
            "owner": obj.get("owner"),
            "connected_accounts": obj.get("connected_accounts"),
            "api_base_url": obj.get("api_base_url"),
            "account": obj.get("account"),
            "openapi_json_scheme_url": obj.get("openapi_json_scheme_url"),
            "api_docs_url": obj.get("api_docs_url"),
            "countries": obj.get("countries"),
            "is_global": obj.get("is_global"),
            "is_sandbox": obj.get("is_sandbox") if obj.get("is_sandbox") is not None else False,
            "api_schema": obj.get("api_schema"),
            "is_official": obj.get("is_official"),
            "client_id": obj.get("client_id"),
            "secret": obj.get("secret"),
            "access_token_url": obj.get("access_token_url"),
            "authorize_url": obj.get("authorize_url"),
            "identity_url": obj.get("identity_url"),
            "scope": obj.get("scope") if obj.get("scope") is not None else '',
            "oauth_basic_auth": obj.get("oauth_basic_auth") if obj.get("oauth_basic_auth") is not None else False,
            "oauth_pkce_enabled": obj.get("oauth_pkce_enabled") if obj.get("oauth_pkce_enabled") is not None else False,
            "accept_header": obj.get("accept_header"),
            "api_key": obj.get("api_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_auth_header_name": obj.get("api_auth_header_name"),
            "api_auth_header_key": obj.get("api_auth_header_key"),
            "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": obj.get("hmac_key_format"),
            "status_check_url": obj.get("status_check_url"),
            "wsdl_document_url": obj.get("wsdl_document_url"),
            "wsdl_auth_method": obj.get("wsdl_auth_method"),
            "wsdl_custom_auth": obj.get("wsdl_custom_auth"),
            "extra_headers": obj.get("extra_headers")
        })
        return _obj


