from __future__ import annotations

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

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

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


@_attrs_define
class WorkflowPerformance:
    """Workflow performance metrics

    Attributes:
        workflow_id (str):
        workflow_name (str):
        percentage (float):
        change (float):
        rank (int):
    """

    workflow_id: str
    workflow_name: str
    percentage: float
    change: float
    rank: int
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        workflow_name = self.workflow_name

        percentage = self.percentage

        change = self.change

        rank = self.rank

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "workflow_id": workflow_id,
                "workflow_name": workflow_name,
                "percentage": percentage,
                "change": change,
                "rank": rank,
            }
        )

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        workflow_id = d.pop("workflow_id")

        workflow_name = d.pop("workflow_name")

        percentage = d.pop("percentage")

        change = d.pop("change")

        rank = d.pop("rank")

        workflow_performance = cls(
            workflow_id=workflow_id,
            workflow_name=workflow_name,
            percentage=percentage,
            change=change,
            rank=rank,
        )

        workflow_performance.additional_properties = d
        return workflow_performance

    @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
