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_provision_raw import TypesProvisionRaw
    from ..models.types_provision_specs import TypesProvisionSpecs


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


@_attrs_define
class TypesProvision:
    """
    Attributes:
        field_id (str | Unset):
        amendment (str | Unset): ID for amendment document
        client (str | Unset):
        created_at (str | Unset):
        deleted_at (str | Unset):
        document_customer_id (str | Unset):
        document_provider (str | Unset):
        document_provider_id (str | Unset):
        effective_on (str | Unset):
        effective_until (str | Unset):
        parent_provision (str | Unset): MEPS/PEPS
        plan (str | Unset):
        raw (TypesProvisionRaw | Unset): Raw Provisions
        specs (TypesProvisionSpecs | Unset): DC Standard (401(k), 403(b), MPP)
        team (str | Unset):
        type_ (str | Unset): Original, Amendment, Variation
        variables (list[str] | Unset): List of keys allowed to be changed. Only parent provisions have variables
        version (str | Unset):
        year (int | Unset): Versioning
    """

    field_id: str | Unset = UNSET
    amendment: str | Unset = UNSET
    client: str | Unset = UNSET
    created_at: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    document_customer_id: str | Unset = UNSET
    document_provider: str | Unset = UNSET
    document_provider_id: str | Unset = UNSET
    effective_on: str | Unset = UNSET
    effective_until: str | Unset = UNSET
    parent_provision: str | Unset = UNSET
    plan: str | Unset = UNSET
    raw: TypesProvisionRaw | Unset = UNSET
    specs: TypesProvisionSpecs | Unset = UNSET
    team: str | Unset = UNSET
    type_: str | Unset = UNSET
    variables: list[str] | Unset = UNSET
    version: str | Unset = UNSET
    year: int | 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

        amendment = self.amendment

        client = self.client

        created_at = self.created_at

        deleted_at = self.deleted_at

        document_customer_id = self.document_customer_id

        document_provider = self.document_provider

        document_provider_id = self.document_provider_id

        effective_on = self.effective_on

        effective_until = self.effective_until

        parent_provision = self.parent_provision

        plan = self.plan

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

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

        team = self.team

        type_ = self.type_

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

        version = self.version

        year = self.year

        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 amendment is not UNSET:
            field_dict["amendment"] = amendment
        if client is not UNSET:
            field_dict["client"] = client
        if created_at is not UNSET:
            field_dict["created_at"] = created_at
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if document_customer_id is not UNSET:
            field_dict["document_customer_id"] = document_customer_id
        if document_provider is not UNSET:
            field_dict["document_provider"] = document_provider
        if document_provider_id is not UNSET:
            field_dict["document_provider_id"] = document_provider_id
        if effective_on is not UNSET:
            field_dict["effective_on"] = effective_on
        if effective_until is not UNSET:
            field_dict["effective_until"] = effective_until
        if parent_provision is not UNSET:
            field_dict["parent_provision"] = parent_provision
        if plan is not UNSET:
            field_dict["plan"] = plan
        if raw is not UNSET:
            field_dict["raw"] = raw
        if specs is not UNSET:
            field_dict["specs"] = specs
        if team is not UNSET:
            field_dict["team"] = team
        if type_ is not UNSET:
            field_dict["type"] = type_
        if variables is not UNSET:
            field_dict["variables"] = variables
        if version is not UNSET:
            field_dict["version"] = version
        if year is not UNSET:
            field_dict["year"] = year

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_provision_raw import TypesProvisionRaw
        from ..models.types_provision_specs import TypesProvisionSpecs

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

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

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

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

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

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

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

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

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

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

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

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

        _raw = d.pop("raw", UNSET)
        raw: TypesProvisionRaw | Unset
        if isinstance(_raw, Unset):
            raw = UNSET
        else:
            raw = TypesProvisionRaw.from_dict(_raw)

        _specs = d.pop("specs", UNSET)
        specs: TypesProvisionSpecs | Unset
        if isinstance(_specs, Unset):
            specs = UNSET
        else:
            specs = TypesProvisionSpecs.from_dict(_specs)

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

        type_ = d.pop("type", UNSET)

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

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

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

        types_provision = cls(
            field_id=field_id,
            amendment=amendment,
            client=client,
            created_at=created_at,
            deleted_at=deleted_at,
            document_customer_id=document_customer_id,
            document_provider=document_provider,
            document_provider_id=document_provider_id,
            effective_on=effective_on,
            effective_until=effective_until,
            parent_provision=parent_provision,
            plan=plan,
            raw=raw,
            specs=specs,
            team=team,
            type_=type_,
            variables=variables,
            version=version,
            year=year,
        )

        types_provision.additional_properties = d
        return types_provision

    @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
