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_payroll_report_equation_line import TypesPayrollReportEquationLine


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


@_attrs_define
class TypesPayrollReportEquation:
    """
    Attributes:
        field (str | Unset):
        sources (list[TypesPayrollReportEquationLine] | Unset): See PayrollReportMapping for field definition
    """

    field: str | Unset = UNSET
    sources: list[TypesPayrollReportEquationLine] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        sources: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.sources, Unset):
            sources = []
            for sources_item_data in self.sources:
                sources_item = sources_item_data.to_dict()
                sources.append(sources_item)

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if field is not UNSET:
            field_dict["field"] = field
        if sources is not UNSET:
            field_dict["sources"] = sources

        return field_dict

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

        d = dict(src_dict)
        field = d.pop("field", UNSET)

        _sources = d.pop("sources", UNSET)
        sources: list[TypesPayrollReportEquationLine] | Unset = UNSET
        if _sources is not UNSET:
            sources = []
            for sources_item_data in _sources:
                sources_item = TypesPayrollReportEquationLine.from_dict(sources_item_data)

                sources.append(sources_item)

        types_payroll_report_equation = cls(
            field=field,
            sources=sources,
        )

        types_payroll_report_equation.additional_properties = d
        return types_payroll_report_equation

    @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
