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 ..models.finchgo_connection_status_type import FinchgoConnectionStatusType
from ..models.sharedtypes_client_payroll_status import SharedtypesClientPayrollStatus
from ..models.sharedtypes_payroll_provider import SharedtypesPayrollProvider
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.types_address import TypesAddress
    from ..models.types_payroll_api_mapping import TypesPayrollAPIMapping
    from ..models.types_payroll_department import TypesPayrollDepartment
    from ..models.types_payroll_provider import TypesPayrollProvider


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


@_attrs_define
class PkgRoutesCpPayrollConnectionWithProvider:
    """
    Attributes:
        field_id (str | Unset):
        active (bool | Unset):
        assignee (str | Unset):
        client (str | Unset):
        client_name (str | Unset):
        connect360 (bool | Unset):
        connected_by (str | Unset):
        connection_id (str | Unset): Finch Connect ID
        created_at (str | Unset):
        credentials (str | Unset):
        deleted_at (str | Unset):
        departments (list[TypesPayrollDepartment] | Unset):
        error (str | Unset):
        finch_message (str | Unset):
        finch_status (FinchgoConnectionStatusType | Unset):
        frequency (str | Unset):
        integration (SharedtypesPayrollProvider | Unset):
        last_sync (str | Unset):
        locations (list[TypesAddress] | Unset):
        locked_at (str | Unset):
        mapping (list[TypesPayrollAPIMapping] | Unset):
        mapping_status (str | Unset):
        message (str | Unset):
        missing_mapping (bool | Unset):
        pending_reports (int | Unset):
        provider (str | Unset):
        provider_information (TypesPayrollProvider | Unset):
        source (str | Unset):
        status (SharedtypesClientPayrollStatus | Unset):
        team (str | Unset):
        team_name (str | Unset):
        trigger (str | Unset): The trigger that initiated the sync
        updated_at (str | Unset):
    """

    field_id: str | Unset = UNSET
    active: bool | Unset = UNSET
    assignee: str | Unset = UNSET
    client: str | Unset = UNSET
    client_name: str | Unset = UNSET
    connect360: bool | Unset = UNSET
    connected_by: str | Unset = UNSET
    connection_id: str | Unset = UNSET
    created_at: str | Unset = UNSET
    credentials: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    departments: list[TypesPayrollDepartment] | Unset = UNSET
    error: str | Unset = UNSET
    finch_message: str | Unset = UNSET
    finch_status: FinchgoConnectionStatusType | Unset = UNSET
    frequency: str | Unset = UNSET
    integration: SharedtypesPayrollProvider | Unset = UNSET
    last_sync: str | Unset = UNSET
    locations: list[TypesAddress] | Unset = UNSET
    locked_at: str | Unset = UNSET
    mapping: list[TypesPayrollAPIMapping] | Unset = UNSET
    mapping_status: str | Unset = UNSET
    message: str | Unset = UNSET
    missing_mapping: bool | Unset = UNSET
    pending_reports: int | Unset = UNSET
    provider: str | Unset = UNSET
    provider_information: TypesPayrollProvider | Unset = UNSET
    source: str | Unset = UNSET
    status: SharedtypesClientPayrollStatus | Unset = UNSET
    team: str | Unset = UNSET
    team_name: str | Unset = UNSET
    trigger: str | Unset = UNSET
    updated_at: 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

        active = self.active

        assignee = self.assignee

        client = self.client

        client_name = self.client_name

        connect360 = self.connect360

        connected_by = self.connected_by

        connection_id = self.connection_id

        created_at = self.created_at

        credentials = self.credentials

        deleted_at = self.deleted_at

        departments: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.departments, Unset):
            departments = []
            for departments_item_data in self.departments:
                departments_item = departments_item_data.to_dict()
                departments.append(departments_item)

        error = self.error

        finch_message = self.finch_message

        finch_status: str | Unset = UNSET
        if not isinstance(self.finch_status, Unset):
            finch_status = self.finch_status.value

        frequency = self.frequency

        integration: str | Unset = UNSET
        if not isinstance(self.integration, Unset):
            integration = self.integration.value

        last_sync = self.last_sync

        locations: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.locations, Unset):
            locations = []
            for locations_item_data in self.locations:
                locations_item = locations_item_data.to_dict()
                locations.append(locations_item)

        locked_at = self.locked_at

        mapping: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.mapping, Unset):
            mapping = []
            for mapping_item_data in self.mapping:
                mapping_item = mapping_item_data.to_dict()
                mapping.append(mapping_item)

        mapping_status = self.mapping_status

        message = self.message

        missing_mapping = self.missing_mapping

        pending_reports = self.pending_reports

        provider = self.provider

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

        source = self.source

        status: str | Unset = UNSET
        if not isinstance(self.status, Unset):
            status = self.status.value

        team = self.team

        team_name = self.team_name

        trigger = self.trigger

        updated_at = self.updated_at

        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 active is not UNSET:
            field_dict["active"] = active
        if assignee is not UNSET:
            field_dict["assignee"] = assignee
        if client is not UNSET:
            field_dict["client"] = client
        if client_name is not UNSET:
            field_dict["client_name"] = client_name
        if connect360 is not UNSET:
            field_dict["connect360"] = connect360
        if connected_by is not UNSET:
            field_dict["connected_by"] = connected_by
        if connection_id is not UNSET:
            field_dict["connection_id"] = connection_id
        if created_at is not UNSET:
            field_dict["created_at"] = created_at
        if credentials is not UNSET:
            field_dict["credentials"] = credentials
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if departments is not UNSET:
            field_dict["departments"] = departments
        if error is not UNSET:
            field_dict["error"] = error
        if finch_message is not UNSET:
            field_dict["finch_message"] = finch_message
        if finch_status is not UNSET:
            field_dict["finch_status"] = finch_status
        if frequency is not UNSET:
            field_dict["frequency"] = frequency
        if integration is not UNSET:
            field_dict["integration"] = integration
        if last_sync is not UNSET:
            field_dict["last_sync"] = last_sync
        if locations is not UNSET:
            field_dict["locations"] = locations
        if locked_at is not UNSET:
            field_dict["locked_at"] = locked_at
        if mapping is not UNSET:
            field_dict["mapping"] = mapping
        if mapping_status is not UNSET:
            field_dict["mapping_status"] = mapping_status
        if message is not UNSET:
            field_dict["message"] = message
        if missing_mapping is not UNSET:
            field_dict["missing_mapping"] = missing_mapping
        if pending_reports is not UNSET:
            field_dict["pending_reports"] = pending_reports
        if provider is not UNSET:
            field_dict["provider"] = provider
        if provider_information is not UNSET:
            field_dict["provider_information"] = provider_information
        if source is not UNSET:
            field_dict["source"] = source
        if status is not UNSET:
            field_dict["status"] = status
        if team is not UNSET:
            field_dict["team"] = team
        if team_name is not UNSET:
            field_dict["team_name"] = team_name
        if trigger is not UNSET:
            field_dict["trigger"] = trigger
        if updated_at is not UNSET:
            field_dict["updated_at"] = updated_at

        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_payroll_api_mapping import TypesPayrollAPIMapping
        from ..models.types_payroll_department import TypesPayrollDepartment
        from ..models.types_payroll_provider import TypesPayrollProvider

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

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

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

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

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

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

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

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

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

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

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

        _departments = d.pop("departments", UNSET)
        departments: list[TypesPayrollDepartment] | Unset = UNSET
        if _departments is not UNSET:
            departments = []
            for departments_item_data in _departments:
                departments_item = TypesPayrollDepartment.from_dict(departments_item_data)

                departments.append(departments_item)

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

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

        _finch_status = d.pop("finch_status", UNSET)
        finch_status: FinchgoConnectionStatusType | Unset
        if isinstance(_finch_status, Unset):
            finch_status = UNSET
        else:
            finch_status = FinchgoConnectionStatusType(_finch_status)

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

        _integration = d.pop("integration", UNSET)
        integration: SharedtypesPayrollProvider | Unset
        if isinstance(_integration, Unset):
            integration = UNSET
        else:
            integration = SharedtypesPayrollProvider(_integration)

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

        _locations = d.pop("locations", UNSET)
        locations: list[TypesAddress] | Unset = UNSET
        if _locations is not UNSET:
            locations = []
            for locations_item_data in _locations:
                locations_item = TypesAddress.from_dict(locations_item_data)

                locations.append(locations_item)

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

        _mapping = d.pop("mapping", UNSET)
        mapping: list[TypesPayrollAPIMapping] | Unset = UNSET
        if _mapping is not UNSET:
            mapping = []
            for mapping_item_data in _mapping:
                mapping_item = TypesPayrollAPIMapping.from_dict(mapping_item_data)

                mapping.append(mapping_item)

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

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

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

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

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

        _provider_information = d.pop("provider_information", UNSET)
        provider_information: TypesPayrollProvider | Unset
        if isinstance(_provider_information, Unset):
            provider_information = UNSET
        else:
            provider_information = TypesPayrollProvider.from_dict(_provider_information)

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

        _status = d.pop("status", UNSET)
        status: SharedtypesClientPayrollStatus | Unset
        if isinstance(_status, Unset):
            status = UNSET
        else:
            status = SharedtypesClientPayrollStatus(_status)

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

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

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

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

        pkg_routes_cp_payroll_connection_with_provider = cls(
            field_id=field_id,
            active=active,
            assignee=assignee,
            client=client,
            client_name=client_name,
            connect360=connect360,
            connected_by=connected_by,
            connection_id=connection_id,
            created_at=created_at,
            credentials=credentials,
            deleted_at=deleted_at,
            departments=departments,
            error=error,
            finch_message=finch_message,
            finch_status=finch_status,
            frequency=frequency,
            integration=integration,
            last_sync=last_sync,
            locations=locations,
            locked_at=locked_at,
            mapping=mapping,
            mapping_status=mapping_status,
            message=message,
            missing_mapping=missing_mapping,
            pending_reports=pending_reports,
            provider=provider,
            provider_information=provider_information,
            source=source,
            status=status,
            team=team,
            team_name=team_name,
            trigger=trigger,
            updated_at=updated_at,
        )

        pkg_routes_cp_payroll_connection_with_provider.additional_properties = d
        return pkg_routes_cp_payroll_connection_with_provider

    @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
