from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.module_config import ModuleConfig


T = TypeVar("T", bound="Module")


@_attrs_define
class Module:
    """
    Attributes:
        field_id (str | Unset): MongoDB ObjectId
        name (str | Unset):
        icon (str | Unset):
        description (str | Unset):
        creator (str | Unset): MongoDB ObjectId
        creator_name (str | Unset):
        rate (float | Unset):
        usage (float | Unset):
        trainer (bool | Unset):
        trainer_config (list[ModuleConfig] | Unset):
        config (list[ModuleConfig] | Unset):
        input_ (str | Unset):
        task_url (str | Unset):
        key (str | Unset):
        url (str | Unset):
        trainer_url (str | Unset):
        public (bool | Unset):
        topic (str | Unset):
        account_threshold (float | Unset):
        cloud_task_queue_name (str | Unset):
        cloud_run_service_url (str | Unset):
    """

    field_id: str | Unset = UNSET
    name: str | Unset = UNSET
    icon: str | Unset = UNSET
    description: str | Unset = UNSET
    creator: str | Unset = UNSET
    creator_name: str | Unset = UNSET
    rate: float | Unset = UNSET
    usage: float | Unset = UNSET
    trainer: bool | Unset = UNSET
    trainer_config: list[ModuleConfig] | Unset = UNSET
    config: list[ModuleConfig] | Unset = UNSET
    input_: str | Unset = UNSET
    task_url: str | Unset = UNSET
    key: str | Unset = UNSET
    url: str | Unset = UNSET
    trainer_url: str | Unset = UNSET
    public: bool | Unset = UNSET
    topic: str | Unset = UNSET
    account_threshold: float | Unset = UNSET
    cloud_task_queue_name: str | Unset = UNSET
    cloud_run_service_url: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        field_id = self.field_id

        name = self.name

        icon = self.icon

        description = self.description

        creator = self.creator

        creator_name = self.creator_name

        rate = self.rate

        usage = self.usage

        trainer = self.trainer

        trainer_config: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.trainer_config, Unset):
            trainer_config = []
            for trainer_config_item_data in self.trainer_config:
                trainer_config_item = trainer_config_item_data.to_dict()
                trainer_config.append(trainer_config_item)

        config: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.config, Unset):
            config = []
            for config_item_data in self.config:
                config_item = config_item_data.to_dict()
                config.append(config_item)

        input_ = self.input_

        task_url = self.task_url

        key = self.key

        url = self.url

        trainer_url = self.trainer_url

        public = self.public

        topic = self.topic

        account_threshold = self.account_threshold

        cloud_task_queue_name = self.cloud_task_queue_name

        cloud_run_service_url = self.cloud_run_service_url

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if field_id is not UNSET:
            field_dict["_id"] = field_id
        if name is not UNSET:
            field_dict["name"] = name
        if icon is not UNSET:
            field_dict["icon"] = icon
        if description is not UNSET:
            field_dict["description"] = description
        if creator is not UNSET:
            field_dict["creator"] = creator
        if creator_name is not UNSET:
            field_dict["creatorName"] = creator_name
        if rate is not UNSET:
            field_dict["rate"] = rate
        if usage is not UNSET:
            field_dict["usage"] = usage
        if trainer is not UNSET:
            field_dict["trainer"] = trainer
        if trainer_config is not UNSET:
            field_dict["trainerConfig"] = trainer_config
        if config is not UNSET:
            field_dict["config"] = config
        if input_ is not UNSET:
            field_dict["input"] = input_
        if task_url is not UNSET:
            field_dict["taskUrl"] = task_url
        if key is not UNSET:
            field_dict["key"] = key
        if url is not UNSET:
            field_dict["url"] = url
        if trainer_url is not UNSET:
            field_dict["trainer_url"] = trainer_url
        if public is not UNSET:
            field_dict["public"] = public
        if topic is not UNSET:
            field_dict["topic"] = topic
        if account_threshold is not UNSET:
            field_dict["accountThreshold"] = account_threshold
        if cloud_task_queue_name is not UNSET:
            field_dict["cloud_task_queue_name"] = cloud_task_queue_name
        if cloud_run_service_url is not UNSET:
            field_dict["cloud_run_service_url"] = cloud_run_service_url

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.module_config import ModuleConfig

        d = dict(src_dict)
        field_id = d.pop("_id", UNSET)

        name = d.pop("name", UNSET)

        icon = d.pop("icon", UNSET)

        description = d.pop("description", UNSET)

        creator = d.pop("creator", UNSET)

        creator_name = d.pop("creatorName", UNSET)

        rate = d.pop("rate", UNSET)

        usage = d.pop("usage", UNSET)

        trainer = d.pop("trainer", UNSET)

        _trainer_config = d.pop("trainerConfig", UNSET)
        trainer_config: list[ModuleConfig] | Unset = UNSET
        if _trainer_config is not UNSET:
            trainer_config = []
            for trainer_config_item_data in _trainer_config:
                trainer_config_item = ModuleConfig.from_dict(trainer_config_item_data)

                trainer_config.append(trainer_config_item)

        _config = d.pop("config", UNSET)
        config: list[ModuleConfig] | Unset = UNSET
        if _config is not UNSET:
            config = []
            for config_item_data in _config:
                config_item = ModuleConfig.from_dict(config_item_data)

                config.append(config_item)

        input_ = d.pop("input", UNSET)

        task_url = d.pop("taskUrl", UNSET)

        key = d.pop("key", UNSET)

        url = d.pop("url", UNSET)

        trainer_url = d.pop("trainer_url", UNSET)

        public = d.pop("public", UNSET)

        topic = d.pop("topic", UNSET)

        account_threshold = d.pop("accountThreshold", UNSET)

        cloud_task_queue_name = d.pop("cloud_task_queue_name", UNSET)

        cloud_run_service_url = d.pop("cloud_run_service_url", UNSET)

        module = cls(
            field_id=field_id,
            name=name,
            icon=icon,
            description=description,
            creator=creator,
            creator_name=creator_name,
            rate=rate,
            usage=usage,
            trainer=trainer,
            trainer_config=trainer_config,
            config=config,
            input_=input_,
            task_url=task_url,
            key=key,
            url=url,
            trainer_url=trainer_url,
            public=public,
            topic=topic,
            account_threshold=account_threshold,
            cloud_task_queue_name=cloud_task_queue_name,
            cloud_run_service_url=cloud_run_service_url,
        )

        module.additional_properties = d
        return module

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
