# coding: utf-8

"""
    CUA API

    Documentation of API endpoints of CUA

    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from robotnikai.models.integration_type import IntegrationType
from typing import Optional, Set
from typing_extensions import Self

class PatchedIntegration(BaseModel):
    """
    PatchedIntegration
    """ # noqa: E501
    integration_id: Optional[Annotated[str, Field(strict=True, max_length=100)]] = None
    type: Optional[IntegrationType] = None
    name: Optional[Annotated[str, Field(strict=True, max_length=150)]] = None
    tags: Optional[List[StrictStr]] = None
    version: Optional[Annotated[str, Field(strict=True, max_length=10)]] = None
    icon: Optional[StrictStr] = None
    description: Optional[StrictStr] = 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")
    configuration_form: Optional[Any] = None
    activated: Optional[StrictBool] = None
    owner: Optional[StrictStr] = None
    connected_accounts: Optional[StrictInt] = 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=200)]] = None
    authorize_url: Optional[Annotated[str, Field(strict=True, max_length=200)]] = None
    identity_url: Optional[Annotated[str, Field(strict=True, max_length=200)]] = None
    scope: Optional[StrictStr] = None
    basic_auth: Optional[StrictBool] = False
    accept_header: Optional[Annotated[str, Field(strict=True, max_length=50)]] = None
    fetch_userinfo: Optional[Annotated[str, Field(strict=True, max_length=200)]] = None
    api_key: Optional[Annotated[str, Field(strict=True, max_length=200)]] = None
    api_auth_header_name: Optional[Annotated[str, Field(strict=True, max_length=50)]] = 'Bearer'
    api_base_url: Optional[Annotated[str, Field(strict=True, max_length=200)]] = None
    __properties: ClassVar[List[str]] = ["integration_id", "type", "name", "tags", "version", "icon", "description", "account_fields", "dependencies", "configuration_form", "activated", "owner", "connected_accounts", "client_id", "secret", "access_token_url", "authorize_url", "identity_url", "scope", "basic_auth", "accept_header", "fetch_userinfo", "api_key", "api_auth_header_name", "api_base_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 PatchedIntegration 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.
        """
        excluded_fields: Set[str] = set([
            "type",
            "activated",
            "owner",
            "connected_accounts",
        ])

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of PatchedIntegration 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,
            "name": obj.get("name"),
            "tags": obj.get("tags"),
            "version": obj.get("version"),
            "icon": obj.get("icon"),
            "description": obj.get("description"),
            "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"),
            "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"),
            "basic_auth": obj.get("basic_auth") if obj.get("basic_auth") is not None else False,
            "accept_header": obj.get("accept_header"),
            "fetch_userinfo": obj.get("fetch_userinfo"),
            "api_key": obj.get("api_key"),
            "api_auth_header_name": obj.get("api_auth_header_name") if obj.get("api_auth_header_name") is not None else 'Bearer',
            "api_base_url": obj.get("api_base_url")
        })
        return _obj


