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

if TYPE_CHECKING:
    from ..models.get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item_num_matching_employees_type_0 import (
        GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType0,
    )
    from ..models.get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item_num_matching_employees_type_1 import (
        GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType1,
    )
    from ..models.get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item_num_matching_employees_type_2 import (
        GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType2,
    )
    from ..models.get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item_num_matching_employees_type_3 import (
        GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType3,
    )


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


@_attrs_define
class GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0Item:
    """
    Attributes:
        num_matching_employees (GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemN
            umMatchingEmployeesType0 |
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType1
            |
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType2
            | GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesTyp
            e3):
    """

    num_matching_employees: (
        GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType0
        | GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType1
        | GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType2
        | GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType3
    )
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        from ..models.get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item_num_matching_employees_type_0 import (
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType0,
        )
        from ..models.get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item_num_matching_employees_type_1 import (
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType1,
        )
        from ..models.get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item_num_matching_employees_type_2 import (
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType2,
        )

        num_matching_employees: dict[str, Any]
        if isinstance(
            self.num_matching_employees,
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType0,
        ):
            num_matching_employees = self.num_matching_employees.to_dict()
        elif isinstance(
            self.num_matching_employees,
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType1,
        ):
            num_matching_employees = self.num_matching_employees.to_dict()
        elif isinstance(
            self.num_matching_employees,
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType2,
        ):
            num_matching_employees = self.num_matching_employees.to_dict()
        else:
            num_matching_employees = self.num_matching_employees.to_dict()

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "numMatchingEmployees": num_matching_employees,
            }
        )

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item_num_matching_employees_type_0 import (
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType0,
        )
        from ..models.get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item_num_matching_employees_type_1 import (
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType1,
        )
        from ..models.get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item_num_matching_employees_type_2 import (
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType2,
        )
        from ..models.get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item_num_matching_employees_type_3 import (
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType3,
        )

        d = dict(src_dict)

        def _parse_num_matching_employees(
            data: object,
        ) -> (
            GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType0
            | GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType1
            | GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType2
            | GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType3
        ):
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                num_matching_employees_type_0 = GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType0.from_dict(
                    data
                )

                return num_matching_employees_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                num_matching_employees_type_1 = GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType1.from_dict(
                    data
                )

                return num_matching_employees_type_1
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                num_matching_employees_type_2 = GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType2.from_dict(
                    data
                )

                return num_matching_employees_type_2
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            if not isinstance(data, dict):
                raise TypeError()
            num_matching_employees_type_3 = GetCurrentCompaniesInSavedSearchResponse200OutputCompaniesItemRoleCountMatchesType0ItemNumMatchingEmployeesType3.from_dict(
                data
            )

            return num_matching_employees_type_3

        num_matching_employees = _parse_num_matching_employees(d.pop("numMatchingEmployees"))

        get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item = cls(
            num_matching_employees=num_matching_employees,
        )

        get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item.additional_properties = d
        return get_current_companies_in_saved_search_response_200_output_companies_item_role_count_matches_type_0_item

    @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
