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 ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.types_address import TypesAddress


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


@_attrs_define
class TypesLocation:
    """
    Attributes:
        address (TypesAddress | Unset):
        client_payroll (str | Unset):
        code (str | Unset):
        name (str | Unset):
    """

    address: TypesAddress | Unset = UNSET
    client_payroll: str | Unset = UNSET
    code: str | Unset = UNSET
    name: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        client_payroll = self.client_payroll

        code = self.code

        name = self.name

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if address is not UNSET:
            field_dict["address"] = address
        if client_payroll is not UNSET:
            field_dict["client_payroll"] = client_payroll
        if code is not UNSET:
            field_dict["code"] = code
        if name is not UNSET:
            field_dict["name"] = name

        return field_dict

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

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

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

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

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

        types_location = cls(
            address=address,
            client_payroll=client_payroll,
            code=code,
            name=name,
        )

        types_location.additional_properties = d
        return types_location

    @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
