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.types_funnel_stage import TypesFunnelStage


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


@_attrs_define
class TypesFunnel:
    """
    Attributes:
        field_id (str | Unset):
        created_at (str | Unset):
        default_deal_value (float | Unset):
        deleted_at (str | Unset):
        lost_template (str | Unset):
        name (str | Unset):
        stages (list[TypesFunnelStage] | Unset):
        team (str | Unset):
        won_template (str | Unset):
    """

    field_id: str | Unset = UNSET
    created_at: str | Unset = UNSET
    default_deal_value: float | Unset = UNSET
    deleted_at: str | Unset = UNSET
    lost_template: str | Unset = UNSET
    name: str | Unset = UNSET
    stages: list[TypesFunnelStage] | Unset = UNSET
    team: str | Unset = UNSET
    won_template: 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

        created_at = self.created_at

        default_deal_value = self.default_deal_value

        deleted_at = self.deleted_at

        lost_template = self.lost_template

        name = self.name

        stages: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.stages, Unset):
            stages = []
            for stages_item_data in self.stages:
                stages_item = stages_item_data.to_dict()
                stages.append(stages_item)

        team = self.team

        won_template = self.won_template

        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 created_at is not UNSET:
            field_dict["created_at"] = created_at
        if default_deal_value is not UNSET:
            field_dict["default_deal_value"] = default_deal_value
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if lost_template is not UNSET:
            field_dict["lost_template"] = lost_template
        if name is not UNSET:
            field_dict["name"] = name
        if stages is not UNSET:
            field_dict["stages"] = stages
        if team is not UNSET:
            field_dict["team"] = team
        if won_template is not UNSET:
            field_dict["won_template"] = won_template

        return field_dict

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

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

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

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

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

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

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

        _stages = d.pop("stages", UNSET)
        stages: list[TypesFunnelStage] | Unset = UNSET
        if _stages is not UNSET:
            stages = []
            for stages_item_data in _stages:
                stages_item = TypesFunnelStage.from_dict(stages_item_data)

                stages.append(stages_item)

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

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

        types_funnel = cls(
            field_id=field_id,
            created_at=created_at,
            default_deal_value=default_deal_value,
            deleted_at=deleted_at,
            lost_template=lost_template,
            name=name,
            stages=stages,
            team=team,
            won_template=won_template,
        )

        types_funnel.additional_properties = d
        return types_funnel

    @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
