from __future__ import annotations

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

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_address import TypesAddress
    from ..models.types_distribution import TypesDistribution
    from ..models.types_employee_census import TypesEmployeeCensus
    from ..models.types_employee_parser_error import TypesEmployeeParserError
    from ..models.types_employee_plan_data import TypesEmployeePlanData
    from ..models.types_loan import TypesLoan


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


@_attrs_define
class TypesEmployee:
    """
    Attributes:
        field_id (str | Unset):
        address (TypesAddress | Unset):
        birth_date (str | Unset): Dates
        census (TypesEmployeeCensus | Unset):
        client (str | Unset):
        created_at (str | Unset):
        ct_group_code (str | Unset): Control-group testing
        deleted_at (str | Unset):
        distributions (list[TypesDistribution] | Unset):
        email (str | Unset):
        employee_plans_data (list[TypesEmployeePlanData] | Unset): Plans Data
        employment_category (str | Unset):
        employment_type (str | Unset):
        ethnicity (str | Unset):
        finch_ids (list[str] | Unset):
        first_name (str | Unset):
        frozen (bool | Unset):
        gender (str | Unset):
        group (str | Unset): Grouping and other manual configurations
        hire_date (str | Unset):
        is_officer (bool | Unset):
        last_name (str | Unset):
        loan (list[TypesLoan] | Unset):
        middle_name (str | Unset):
        missing_ssn (bool | Unset):
        not_employee (bool | Unset):
        ownership_percentage (float | Unset): Ownership/Family
        parser_errors (list[TypesEmployeeParserError] | Unset):
        phone (str | Unset):
        possible_duplicate (bool | Unset):
        preferred_name (str | Unset):
        principal (str | Unset):
        prior_year_census (TypesEmployeeCensus | Unset):
        rehire_date (str | Unset):
        relationship (str | Unset):
        remote_id (str | Unset):
        ssn (str | Unset): Personal details
        team (str | Unset):
        termination_date (str | Unset):
        title (str | Unset): Employee/employment details (copied over to new census data)
    """

    field_id: str | Unset = UNSET
    address: TypesAddress | Unset = UNSET
    birth_date: str | Unset = UNSET
    census: TypesEmployeeCensus | Unset = UNSET
    client: str | Unset = UNSET
    created_at: str | Unset = UNSET
    ct_group_code: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    distributions: list[TypesDistribution] | Unset = UNSET
    email: str | Unset = UNSET
    employee_plans_data: list[TypesEmployeePlanData] | Unset = UNSET
    employment_category: str | Unset = UNSET
    employment_type: str | Unset = UNSET
    ethnicity: str | Unset = UNSET
    finch_ids: list[str] | Unset = UNSET
    first_name: str | Unset = UNSET
    frozen: bool | Unset = UNSET
    gender: str | Unset = UNSET
    group: str | Unset = UNSET
    hire_date: str | Unset = UNSET
    is_officer: bool | Unset = UNSET
    last_name: str | Unset = UNSET
    loan: list[TypesLoan] | Unset = UNSET
    middle_name: str | Unset = UNSET
    missing_ssn: bool | Unset = UNSET
    not_employee: bool | Unset = UNSET
    ownership_percentage: float | Unset = UNSET
    parser_errors: list[TypesEmployeeParserError] | Unset = UNSET
    phone: str | Unset = UNSET
    possible_duplicate: bool | Unset = UNSET
    preferred_name: str | Unset = UNSET
    principal: str | Unset = UNSET
    prior_year_census: TypesEmployeeCensus | Unset = UNSET
    rehire_date: str | Unset = UNSET
    relationship: str | Unset = UNSET
    remote_id: str | Unset = UNSET
    ssn: str | Unset = UNSET
    team: str | Unset = UNSET
    termination_date: str | Unset = UNSET
    title: 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

        address: dict[str, Any] | Unset = UNSET
        if not isinstance(self.address, Unset):
            address = self.address.to_dict()

        birth_date = self.birth_date

        census: dict[str, Any] | Unset = UNSET
        if not isinstance(self.census, Unset):
            census = self.census.to_dict()

        client = self.client

        created_at = self.created_at

        ct_group_code = self.ct_group_code

        deleted_at = self.deleted_at

        distributions: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.distributions, Unset):
            distributions = []
            for distributions_item_data in self.distributions:
                distributions_item = distributions_item_data.to_dict()
                distributions.append(distributions_item)

        email = self.email

        employee_plans_data: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.employee_plans_data, Unset):
            employee_plans_data = []
            for employee_plans_data_item_data in self.employee_plans_data:
                employee_plans_data_item = employee_plans_data_item_data.to_dict()
                employee_plans_data.append(employee_plans_data_item)

        employment_category = self.employment_category

        employment_type = self.employment_type

        ethnicity = self.ethnicity

        finch_ids: list[str] | Unset = UNSET
        if not isinstance(self.finch_ids, Unset):
            finch_ids = self.finch_ids

        first_name = self.first_name

        frozen = self.frozen

        gender = self.gender

        group = self.group

        hire_date = self.hire_date

        is_officer = self.is_officer

        last_name = self.last_name

        loan: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.loan, Unset):
            loan = []
            for loan_item_data in self.loan:
                loan_item = loan_item_data.to_dict()
                loan.append(loan_item)

        middle_name = self.middle_name

        missing_ssn = self.missing_ssn

        not_employee = self.not_employee

        ownership_percentage = self.ownership_percentage

        parser_errors: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.parser_errors, Unset):
            parser_errors = []
            for parser_errors_item_data in self.parser_errors:
                parser_errors_item = parser_errors_item_data.to_dict()
                parser_errors.append(parser_errors_item)

        phone = self.phone

        possible_duplicate = self.possible_duplicate

        preferred_name = self.preferred_name

        principal = self.principal

        prior_year_census: dict[str, Any] | Unset = UNSET
        if not isinstance(self.prior_year_census, Unset):
            prior_year_census = self.prior_year_census.to_dict()

        rehire_date = self.rehire_date

        relationship = self.relationship

        remote_id = self.remote_id

        ssn = self.ssn

        team = self.team

        termination_date = self.termination_date

        title = self.title

        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 address is not UNSET:
            field_dict["address"] = address
        if birth_date is not UNSET:
            field_dict["birth_date"] = birth_date
        if census is not UNSET:
            field_dict["census"] = census
        if client is not UNSET:
            field_dict["client"] = client
        if created_at is not UNSET:
            field_dict["created_at"] = created_at
        if ct_group_code is not UNSET:
            field_dict["ct_group_code"] = ct_group_code
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if distributions is not UNSET:
            field_dict["distributions"] = distributions
        if email is not UNSET:
            field_dict["email"] = email
        if employee_plans_data is not UNSET:
            field_dict["employee_plans_data"] = employee_plans_data
        if employment_category is not UNSET:
            field_dict["employment_category"] = employment_category
        if employment_type is not UNSET:
            field_dict["employment_type"] = employment_type
        if ethnicity is not UNSET:
            field_dict["ethnicity"] = ethnicity
        if finch_ids is not UNSET:
            field_dict["finch_ids"] = finch_ids
        if first_name is not UNSET:
            field_dict["first_name"] = first_name
        if frozen is not UNSET:
            field_dict["frozen"] = frozen
        if gender is not UNSET:
            field_dict["gender"] = gender
        if group is not UNSET:
            field_dict["group"] = group
        if hire_date is not UNSET:
            field_dict["hire_date"] = hire_date
        if is_officer is not UNSET:
            field_dict["is_officer"] = is_officer
        if last_name is not UNSET:
            field_dict["last_name"] = last_name
        if loan is not UNSET:
            field_dict["loan"] = loan
        if middle_name is not UNSET:
            field_dict["middle_name"] = middle_name
        if missing_ssn is not UNSET:
            field_dict["missing_ssn"] = missing_ssn
        if not_employee is not UNSET:
            field_dict["not_employee"] = not_employee
        if ownership_percentage is not UNSET:
            field_dict["ownership_percentage"] = ownership_percentage
        if parser_errors is not UNSET:
            field_dict["parser_errors"] = parser_errors
        if phone is not UNSET:
            field_dict["phone"] = phone
        if possible_duplicate is not UNSET:
            field_dict["possible_duplicate"] = possible_duplicate
        if preferred_name is not UNSET:
            field_dict["preferred_name"] = preferred_name
        if principal is not UNSET:
            field_dict["principal"] = principal
        if prior_year_census is not UNSET:
            field_dict["prior_year_census"] = prior_year_census
        if rehire_date is not UNSET:
            field_dict["rehire_date"] = rehire_date
        if relationship is not UNSET:
            field_dict["relationship"] = relationship
        if remote_id is not UNSET:
            field_dict["remote_id"] = remote_id
        if ssn is not UNSET:
            field_dict["ssn"] = ssn
        if team is not UNSET:
            field_dict["team"] = team
        if termination_date is not UNSET:
            field_dict["termination_date"] = termination_date
        if title is not UNSET:
            field_dict["title"] = title

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_address import TypesAddress
        from ..models.types_distribution import TypesDistribution
        from ..models.types_employee_census import TypesEmployeeCensus
        from ..models.types_employee_parser_error import TypesEmployeeParserError
        from ..models.types_employee_plan_data import TypesEmployeePlanData
        from ..models.types_loan import TypesLoan

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

        _address = d.pop("address", UNSET)
        address: TypesAddress | Unset
        if isinstance(_address, Unset):
            address = UNSET
        else:
            address = TypesAddress.from_dict(_address)

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

        _census = d.pop("census", UNSET)
        census: TypesEmployeeCensus | Unset
        if isinstance(_census, Unset):
            census = UNSET
        else:
            census = TypesEmployeeCensus.from_dict(_census)

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

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

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

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

        _distributions = d.pop("distributions", UNSET)
        distributions: list[TypesDistribution] | Unset = UNSET
        if _distributions is not UNSET:
            distributions = []
            for distributions_item_data in _distributions:
                distributions_item = TypesDistribution.from_dict(distributions_item_data)

                distributions.append(distributions_item)

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

        _employee_plans_data = d.pop("employee_plans_data", UNSET)
        employee_plans_data: list[TypesEmployeePlanData] | Unset = UNSET
        if _employee_plans_data is not UNSET:
            employee_plans_data = []
            for employee_plans_data_item_data in _employee_plans_data:
                employee_plans_data_item = TypesEmployeePlanData.from_dict(employee_plans_data_item_data)

                employee_plans_data.append(employee_plans_data_item)

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

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

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

        finch_ids = cast(list[str], d.pop("finch_ids", UNSET))

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

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

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

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

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

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

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

        _loan = d.pop("loan", UNSET)
        loan: list[TypesLoan] | Unset = UNSET
        if _loan is not UNSET:
            loan = []
            for loan_item_data in _loan:
                loan_item = TypesLoan.from_dict(loan_item_data)

                loan.append(loan_item)

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

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

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

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

        _parser_errors = d.pop("parser_errors", UNSET)
        parser_errors: list[TypesEmployeeParserError] | Unset = UNSET
        if _parser_errors is not UNSET:
            parser_errors = []
            for parser_errors_item_data in _parser_errors:
                parser_errors_item = TypesEmployeeParserError.from_dict(parser_errors_item_data)

                parser_errors.append(parser_errors_item)

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

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

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

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

        _prior_year_census = d.pop("prior_year_census", UNSET)
        prior_year_census: TypesEmployeeCensus | Unset
        if isinstance(_prior_year_census, Unset):
            prior_year_census = UNSET
        else:
            prior_year_census = TypesEmployeeCensus.from_dict(_prior_year_census)

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

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

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

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

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

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

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

        types_employee = cls(
            field_id=field_id,
            address=address,
            birth_date=birth_date,
            census=census,
            client=client,
            created_at=created_at,
            ct_group_code=ct_group_code,
            deleted_at=deleted_at,
            distributions=distributions,
            email=email,
            employee_plans_data=employee_plans_data,
            employment_category=employment_category,
            employment_type=employment_type,
            ethnicity=ethnicity,
            finch_ids=finch_ids,
            first_name=first_name,
            frozen=frozen,
            gender=gender,
            group=group,
            hire_date=hire_date,
            is_officer=is_officer,
            last_name=last_name,
            loan=loan,
            middle_name=middle_name,
            missing_ssn=missing_ssn,
            not_employee=not_employee,
            ownership_percentage=ownership_percentage,
            parser_errors=parser_errors,
            phone=phone,
            possible_duplicate=possible_duplicate,
            preferred_name=preferred_name,
            principal=principal,
            prior_year_census=prior_year_census,
            rehire_date=rehire_date,
            relationship=relationship,
            remote_id=remote_id,
            ssn=ssn,
            team=team,
            termination_date=termination_date,
            title=title,
        )

        types_employee.additional_properties = d
        return types_employee

    @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
