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_activity import TypesActivity
    from ..models.types_address import TypesAddress
    from ..models.types_employee_census_edits import TypesEmployeeCensusEdits
    from ..models.types_employee_census_skipped import TypesEmployeeCensusSkipped
    from ..models.types_plan_data import TypesPlanData
    from ..models.types_short_employee_census_error import TypesShortEmployeeCensusError


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


@_attrs_define
class TypesEmployeeCensus:
    """
    Attributes:
        field_id (str | Unset):
        activity (list[TypesActivity] | Unset): Keep track of activity
        address (TypesAddress | Unset):
        birth_date (str | Unset): Dates
        cleared (list[str] | Unset): Keep track of the cleared errors so they don't show up again for the TPA or the
            client
        client (str | Unset):
        created_at (str | Unset):
        ct_group_code (str | Unset): Control-group testing
        deleted_at (str | Unset):
        edits (TypesEmployeeCensusEdits | Unset): If a user manually edits a value, we record the original value here
            and replace the transaction with the new value
        email (str | Unset):
        employee (str | Unset):
        employment_category (str | Unset):
        employment_type (str | Unset):
        errors (list[TypesShortEmployeeCensusError] | Unset): Recorded census scrubbing errors
        ethnicity (str | Unset):
        first_name (str | Unset):
        gender (str | Unset):
        group (str | Unset): Division Code
        hire_date (str | Unset):
        is_officer (bool | Unset):
        last_name (str | Unset):
        loan_amount (float | Unset):
        loan_balance (float | Unset):
        loan_disbursement_date (str | Unset): Loan data
        loan_installment (float | Unset):
        middle_name (str | Unset): Other data we're collecting in case we need them
        not_employee (bool | Unset):
        other_employers (list[str] | Unset): Are they employed by any other entities?
        ownership_percentage (float | Unset): Ownership/Family
        phone (str | Unset):
        plans_data (list[TypesPlanData] | Unset): Plan Data
        possible_termination_date (str | Unset): In case we don't have a termination date, we can provide a possible
            termination date based on the last payroll.
        preferred_name (str | Unset):
        principal (str | Unset):
        py (int | Unset):
        rehire_date (str | Unset):
        relationship (str | Unset):
        skipped (TypesEmployeeCensusSkipped | Unset): Keep track of skipped fields for overrides
        ssn (str | Unset): Personal details
        team (str | Unset):
        termination_date (str | Unset):
        termination_reason (str | Unset):
        title (str | Unset):
    """

    field_id: str | Unset = UNSET
    activity: list[TypesActivity] | Unset = UNSET
    address: TypesAddress | Unset = UNSET
    birth_date: str | Unset = UNSET
    cleared: list[str] | Unset = UNSET
    client: str | Unset = UNSET
    created_at: str | Unset = UNSET
    ct_group_code: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    edits: TypesEmployeeCensusEdits | Unset = UNSET
    email: str | Unset = UNSET
    employee: str | Unset = UNSET
    employment_category: str | Unset = UNSET
    employment_type: str | Unset = UNSET
    errors: list[TypesShortEmployeeCensusError] | Unset = UNSET
    ethnicity: str | Unset = UNSET
    first_name: str | 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_amount: float | Unset = UNSET
    loan_balance: float | Unset = UNSET
    loan_disbursement_date: str | Unset = UNSET
    loan_installment: float | Unset = UNSET
    middle_name: str | Unset = UNSET
    not_employee: bool | Unset = UNSET
    other_employers: list[str] | Unset = UNSET
    ownership_percentage: float | Unset = UNSET
    phone: str | Unset = UNSET
    plans_data: list[TypesPlanData] | Unset = UNSET
    possible_termination_date: str | Unset = UNSET
    preferred_name: str | Unset = UNSET
    principal: str | Unset = UNSET
    py: int | Unset = UNSET
    rehire_date: str | Unset = UNSET
    relationship: str | Unset = UNSET
    skipped: TypesEmployeeCensusSkipped | Unset = UNSET
    ssn: str | Unset = UNSET
    team: str | Unset = UNSET
    termination_date: str | Unset = UNSET
    termination_reason: 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

        activity: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.activity, Unset):
            activity = []
            for activity_item_data in self.activity:
                activity_item = activity_item_data.to_dict()
                activity.append(activity_item)

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

        birth_date = self.birth_date

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

        client = self.client

        created_at = self.created_at

        ct_group_code = self.ct_group_code

        deleted_at = self.deleted_at

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

        email = self.email

        employee = self.employee

        employment_category = self.employment_category

        employment_type = self.employment_type

        errors: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.errors, Unset):
            errors = []
            for errors_item_data in self.errors:
                errors_item = errors_item_data.to_dict()
                errors.append(errors_item)

        ethnicity = self.ethnicity

        first_name = self.first_name

        gender = self.gender

        group = self.group

        hire_date = self.hire_date

        is_officer = self.is_officer

        last_name = self.last_name

        loan_amount = self.loan_amount

        loan_balance = self.loan_balance

        loan_disbursement_date = self.loan_disbursement_date

        loan_installment = self.loan_installment

        middle_name = self.middle_name

        not_employee = self.not_employee

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

        ownership_percentage = self.ownership_percentage

        phone = self.phone

        plans_data: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.plans_data, Unset):
            plans_data = []
            for plans_data_item_data in self.plans_data:
                plans_data_item = plans_data_item_data.to_dict()
                plans_data.append(plans_data_item)

        possible_termination_date = self.possible_termination_date

        preferred_name = self.preferred_name

        principal = self.principal

        py = self.py

        rehire_date = self.rehire_date

        relationship = self.relationship

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

        ssn = self.ssn

        team = self.team

        termination_date = self.termination_date

        termination_reason = self.termination_reason

        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 activity is not UNSET:
            field_dict["activity"] = activity
        if address is not UNSET:
            field_dict["address"] = address
        if birth_date is not UNSET:
            field_dict["birth_date"] = birth_date
        if cleared is not UNSET:
            field_dict["cleared"] = cleared
        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 edits is not UNSET:
            field_dict["edits"] = edits
        if email is not UNSET:
            field_dict["email"] = email
        if employee is not UNSET:
            field_dict["employee"] = employee
        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 errors is not UNSET:
            field_dict["errors"] = errors
        if ethnicity is not UNSET:
            field_dict["ethnicity"] = ethnicity
        if first_name is not UNSET:
            field_dict["first_name"] = first_name
        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_amount is not UNSET:
            field_dict["loan_amount"] = loan_amount
        if loan_balance is not UNSET:
            field_dict["loan_balance"] = loan_balance
        if loan_disbursement_date is not UNSET:
            field_dict["loan_disbursement_date"] = loan_disbursement_date
        if loan_installment is not UNSET:
            field_dict["loan_installment"] = loan_installment
        if middle_name is not UNSET:
            field_dict["middle_name"] = middle_name
        if not_employee is not UNSET:
            field_dict["not_employee"] = not_employee
        if other_employers is not UNSET:
            field_dict["other_employers"] = other_employers
        if ownership_percentage is not UNSET:
            field_dict["ownership_percentage"] = ownership_percentage
        if phone is not UNSET:
            field_dict["phone"] = phone
        if plans_data is not UNSET:
            field_dict["plans_data"] = plans_data
        if possible_termination_date is not UNSET:
            field_dict["possible_termination_date"] = possible_termination_date
        if preferred_name is not UNSET:
            field_dict["preferred_name"] = preferred_name
        if principal is not UNSET:
            field_dict["principal"] = principal
        if py is not UNSET:
            field_dict["py"] = py
        if rehire_date is not UNSET:
            field_dict["rehire_date"] = rehire_date
        if relationship is not UNSET:
            field_dict["relationship"] = relationship
        if skipped is not UNSET:
            field_dict["skipped"] = skipped
        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 termination_reason is not UNSET:
            field_dict["termination_reason"] = termination_reason
        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_activity import TypesActivity
        from ..models.types_address import TypesAddress
        from ..models.types_employee_census_edits import TypesEmployeeCensusEdits
        from ..models.types_employee_census_skipped import TypesEmployeeCensusSkipped
        from ..models.types_plan_data import TypesPlanData
        from ..models.types_short_employee_census_error import TypesShortEmployeeCensusError

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

        _activity = d.pop("activity", UNSET)
        activity: list[TypesActivity] | Unset = UNSET
        if _activity is not UNSET:
            activity = []
            for activity_item_data in _activity:
                activity_item = TypesActivity.from_dict(activity_item_data)

                activity.append(activity_item)

        _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)

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

        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)

        _edits = d.pop("edits", UNSET)
        edits: TypesEmployeeCensusEdits | Unset
        if isinstance(_edits, Unset):
            edits = UNSET
        else:
            edits = TypesEmployeeCensusEdits.from_dict(_edits)

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

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

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

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

        _errors = d.pop("errors", UNSET)
        errors: list[TypesShortEmployeeCensusError] | Unset = UNSET
        if _errors is not UNSET:
            errors = []
            for errors_item_data in _errors:
                errors_item = TypesShortEmployeeCensusError.from_dict(errors_item_data)

                errors.append(errors_item)

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

        first_name = d.pop("first_name", 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_amount = d.pop("loan_amount", UNSET)

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

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

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

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

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

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

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

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

        _plans_data = d.pop("plans_data", UNSET)
        plans_data: list[TypesPlanData] | Unset = UNSET
        if _plans_data is not UNSET:
            plans_data = []
            for plans_data_item_data in _plans_data:
                plans_data_item = TypesPlanData.from_dict(plans_data_item_data)

                plans_data.append(plans_data_item)

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

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

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

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

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

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

        _skipped = d.pop("skipped", UNSET)
        skipped: TypesEmployeeCensusSkipped | Unset
        if isinstance(_skipped, Unset):
            skipped = UNSET
        else:
            skipped = TypesEmployeeCensusSkipped.from_dict(_skipped)

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

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

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

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

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

        types_employee_census = cls(
            field_id=field_id,
            activity=activity,
            address=address,
            birth_date=birth_date,
            cleared=cleared,
            client=client,
            created_at=created_at,
            ct_group_code=ct_group_code,
            deleted_at=deleted_at,
            edits=edits,
            email=email,
            employee=employee,
            employment_category=employment_category,
            employment_type=employment_type,
            errors=errors,
            ethnicity=ethnicity,
            first_name=first_name,
            gender=gender,
            group=group,
            hire_date=hire_date,
            is_officer=is_officer,
            last_name=last_name,
            loan_amount=loan_amount,
            loan_balance=loan_balance,
            loan_disbursement_date=loan_disbursement_date,
            loan_installment=loan_installment,
            middle_name=middle_name,
            not_employee=not_employee,
            other_employers=other_employers,
            ownership_percentage=ownership_percentage,
            phone=phone,
            plans_data=plans_data,
            possible_termination_date=possible_termination_date,
            preferred_name=preferred_name,
            principal=principal,
            py=py,
            rehire_date=rehire_date,
            relationship=relationship,
            skipped=skipped,
            ssn=ssn,
            team=team,
            termination_date=termination_date,
            termination_reason=termination_reason,
            title=title,
        )

        types_employee_census.additional_properties = d
        return types_employee_census

    @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
