# coding: utf-8

"""
    Kestra EE

    All API operations, except for Superadmin-only endpoints, require a tenant identifier in the HTTP path.<br/> Endpoints designated as Superadmin-only are not tenant-scoped.

    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import regex as re
import json

from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from kestrapy.models.plugin_plugin_element_metadata import PluginPluginElementMetadata
from kestrapy.models.plugin_sub_group_plugin_category import PluginSubGroupPluginCategory
from typing import Optional, Set
from typing_extensions import Self

class Plugin(BaseModel):
    """
    Plugin
    """ # noqa: E501
    name: Optional[StrictStr] = None
    title: Optional[StrictStr] = None
    description: Optional[StrictStr] = None
    license: Optional[StrictStr] = None
    long_description: Optional[StrictStr] = Field(default=None, alias="longDescription")
    group: Optional[StrictStr] = None
    version: Optional[StrictStr] = None
    manifest: Optional[Dict[str, StrictStr]] = None
    guides: Optional[List[StrictStr]] = None
    aliases: Optional[List[StrictStr]] = None
    tasks: Optional[List[PluginPluginElementMetadata]] = None
    triggers: Optional[List[PluginPluginElementMetadata]] = None
    conditions: Optional[List[PluginPluginElementMetadata]] = None
    controllers: Optional[List[PluginPluginElementMetadata]] = None
    storages: Optional[List[PluginPluginElementMetadata]] = None
    secrets: Optional[List[PluginPluginElementMetadata]] = None
    task_runners: Optional[List[PluginPluginElementMetadata]] = Field(default=None, alias="taskRunners")
    apps: Optional[List[PluginPluginElementMetadata]] = None
    app_blocks: Optional[List[PluginPluginElementMetadata]] = Field(default=None, alias="appBlocks")
    charts: Optional[List[PluginPluginElementMetadata]] = None
    data_filters: Optional[List[PluginPluginElementMetadata]] = Field(default=None, alias="dataFilters")
    data_filters_kpi: Optional[List[PluginPluginElementMetadata]] = Field(default=None, alias="dataFiltersKPI")
    log_exporters: Optional[List[PluginPluginElementMetadata]] = Field(default=None, alias="logExporters")
    additional_plugins: Optional[List[PluginPluginElementMetadata]] = Field(default=None, alias="additionalPlugins")
    categories: Optional[List[PluginSubGroupPluginCategory]] = None
    sub_group: Optional[StrictStr] = Field(default=None, alias="subGroup")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["name", "title", "description", "license", "longDescription", "group", "version", "manifest", "guides", "aliases", "tasks", "triggers", "conditions", "controllers", "storages", "secrets", "taskRunners", "apps", "appBlocks", "charts", "dataFilters", "dataFiltersKPI", "logExporters", "additionalPlugins", "categories", "subGroup"]

    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 Plugin 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.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in tasks (list)
        _items = []
        if self.tasks:
            for _item_tasks in self.tasks:
                if _item_tasks:
                    _items.append(_item_tasks.to_dict())
            _dict['tasks'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in triggers (list)
        _items = []
        if self.triggers:
            for _item_triggers in self.triggers:
                if _item_triggers:
                    _items.append(_item_triggers.to_dict())
            _dict['triggers'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in conditions (list)
        _items = []
        if self.conditions:
            for _item_conditions in self.conditions:
                if _item_conditions:
                    _items.append(_item_conditions.to_dict())
            _dict['conditions'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in controllers (list)
        _items = []
        if self.controllers:
            for _item_controllers in self.controllers:
                if _item_controllers:
                    _items.append(_item_controllers.to_dict())
            _dict['controllers'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in storages (list)
        _items = []
        if self.storages:
            for _item_storages in self.storages:
                if _item_storages:
                    _items.append(_item_storages.to_dict())
            _dict['storages'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in secrets (list)
        _items = []
        if self.secrets:
            for _item_secrets in self.secrets:
                if _item_secrets:
                    _items.append(_item_secrets.to_dict())
            _dict['secrets'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in task_runners (list)
        _items = []
        if self.task_runners:
            for _item_task_runners in self.task_runners:
                if _item_task_runners:
                    _items.append(_item_task_runners.to_dict())
            _dict['taskRunners'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in apps (list)
        _items = []
        if self.apps:
            for _item_apps in self.apps:
                if _item_apps:
                    _items.append(_item_apps.to_dict())
            _dict['apps'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in app_blocks (list)
        _items = []
        if self.app_blocks:
            for _item_app_blocks in self.app_blocks:
                if _item_app_blocks:
                    _items.append(_item_app_blocks.to_dict())
            _dict['appBlocks'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in charts (list)
        _items = []
        if self.charts:
            for _item_charts in self.charts:
                if _item_charts:
                    _items.append(_item_charts.to_dict())
            _dict['charts'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in data_filters (list)
        _items = []
        if self.data_filters:
            for _item_data_filters in self.data_filters:
                if _item_data_filters:
                    _items.append(_item_data_filters.to_dict())
            _dict['dataFilters'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in data_filters_kpi (list)
        _items = []
        if self.data_filters_kpi:
            for _item_data_filters_kpi in self.data_filters_kpi:
                if _item_data_filters_kpi:
                    _items.append(_item_data_filters_kpi.to_dict())
            _dict['dataFiltersKPI'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in log_exporters (list)
        _items = []
        if self.log_exporters:
            for _item_log_exporters in self.log_exporters:
                if _item_log_exporters:
                    _items.append(_item_log_exporters.to_dict())
            _dict['logExporters'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in additional_plugins (list)
        _items = []
        if self.additional_plugins:
            for _item_additional_plugins in self.additional_plugins:
                if _item_additional_plugins:
                    _items.append(_item_additional_plugins.to_dict())
            _dict['additionalPlugins'] = _items
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

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

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

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "title": obj.get("title"),
            "description": obj.get("description"),
            "license": obj.get("license"),
            "longDescription": obj.get("longDescription"),
            "group": obj.get("group"),
            "version": obj.get("version"),
            "manifest": obj.get("manifest"),
            "guides": obj.get("guides"),
            "aliases": obj.get("aliases"),
            "tasks": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["tasks"]] if obj.get("tasks") is not None else None,
            "triggers": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["triggers"]] if obj.get("triggers") is not None else None,
            "conditions": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["conditions"]] if obj.get("conditions") is not None else None,
            "controllers": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["controllers"]] if obj.get("controllers") is not None else None,
            "storages": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["storages"]] if obj.get("storages") is not None else None,
            "secrets": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["secrets"]] if obj.get("secrets") is not None else None,
            "taskRunners": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["taskRunners"]] if obj.get("taskRunners") is not None else None,
            "apps": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["apps"]] if obj.get("apps") is not None else None,
            "appBlocks": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["appBlocks"]] if obj.get("appBlocks") is not None else None,
            "charts": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["charts"]] if obj.get("charts") is not None else None,
            "dataFilters": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["dataFilters"]] if obj.get("dataFilters") is not None else None,
            "dataFiltersKPI": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["dataFiltersKPI"]] if obj.get("dataFiltersKPI") is not None else None,
            "logExporters": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["logExporters"]] if obj.get("logExporters") is not None else None,
            "additionalPlugins": [PluginPluginElementMetadata.from_dict(_item) for _item in obj["additionalPlugins"]] if obj.get("additionalPlugins") is not None else None,
            "categories": obj.get("categories"),
            "subGroup": obj.get("subGroup")
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


