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_payroll_api_mapping import TypesPayrollAPIMapping


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


@_attrs_define
class TypesPayrollConfig:
    """
    Attributes:
        active (bool | Unset):
        connect360 (bool | Unset):
        connection_id (str | Unset): Finch Connect ID
        credentials (str | Unset):
        error (str | Unset):
        frequency (str | Unset):
        integration (str | Unset):
        last_sync (str | Unset):
        mapping (list[TypesPayrollAPIMapping] | Unset):
        message (str | Unset):
        pending_reports (int | Unset):
        providers (list[str] | Unset):
        session_expires_at (str | Unset): Finch Connect Session Expiry
        session_id (str | Unset): Finch Connect Session ID
        source (str | Unset):
        statuses (list[str] | Unset):
        trigger (str | Unset): The trigger that initiated the sync
    """

    active: bool | Unset = UNSET
    connect360: bool | Unset = UNSET
    connection_id: str | Unset = UNSET
    credentials: str | Unset = UNSET
    error: str | Unset = UNSET
    frequency: str | Unset = UNSET
    integration: str | Unset = UNSET
    last_sync: str | Unset = UNSET
    mapping: list[TypesPayrollAPIMapping] | Unset = UNSET
    message: str | Unset = UNSET
    pending_reports: int | Unset = UNSET
    providers: list[str] | Unset = UNSET
    session_expires_at: str | Unset = UNSET
    session_id: str | Unset = UNSET
    source: str | Unset = UNSET
    statuses: list[str] | Unset = UNSET
    trigger: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        connect360 = self.connect360

        connection_id = self.connection_id

        credentials = self.credentials

        error = self.error

        frequency = self.frequency

        integration = self.integration

        last_sync = self.last_sync

        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)

        message = self.message

        pending_reports = self.pending_reports

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

        session_expires_at = self.session_expires_at

        session_id = self.session_id

        source = self.source

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

        trigger = self.trigger

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if active is not UNSET:
            field_dict["active"] = active
        if connect360 is not UNSET:
            field_dict["connect360"] = connect360
        if connection_id is not UNSET:
            field_dict["connection_id"] = connection_id
        if credentials is not UNSET:
            field_dict["credentials"] = credentials
        if error is not UNSET:
            field_dict["error"] = error
        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 mapping is not UNSET:
            field_dict["mapping"] = mapping
        if message is not UNSET:
            field_dict["message"] = message
        if pending_reports is not UNSET:
            field_dict["pending_reports"] = pending_reports
        if providers is not UNSET:
            field_dict["providers"] = providers
        if session_expires_at is not UNSET:
            field_dict["session_expires_at"] = session_expires_at
        if session_id is not UNSET:
            field_dict["session_id"] = session_id
        if source is not UNSET:
            field_dict["source"] = source
        if statuses is not UNSET:
            field_dict["statuses"] = statuses
        if trigger is not UNSET:
            field_dict["trigger"] = trigger

        return field_dict

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

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

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

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

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

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

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

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

        last_sync = d.pop("last_sync", 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)

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

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

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

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

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

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

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

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

        types_payroll_config = cls(
            active=active,
            connect360=connect360,
            connection_id=connection_id,
            credentials=credentials,
            error=error,
            frequency=frequency,
            integration=integration,
            last_sync=last_sync,
            mapping=mapping,
            message=message,
            pending_reports=pending_reports,
            providers=providers,
            session_expires_at=session_expires_at,
            session_id=session_id,
            source=source,
            statuses=statuses,
            trigger=trigger,
        )

        types_payroll_config.additional_properties = d
        return types_payroll_config

    @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
