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_rarse_result_mapping import TypesPayrollRarseResultMapping


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


@_attrs_define
class TypesPayrollParseResultSheet:
    """
    Attributes:
        block1_end_index (int | Unset):
        block2_end_index (int | Unset):
        block2_start_index (int | Unset):
        end_indices (list[int] | Unset):
        mapping (list[TypesPayrollRarseResultMapping] | Unset):
        start_indices (list[int] | Unset):
    """

    block1_end_index: int | Unset = UNSET
    block2_end_index: int | Unset = UNSET
    block2_start_index: int | Unset = UNSET
    end_indices: list[int] | Unset = UNSET
    mapping: list[TypesPayrollRarseResultMapping] | Unset = UNSET
    start_indices: list[int] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        block2_end_index = self.block2_end_index

        block2_start_index = self.block2_start_index

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

        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)

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

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if block1_end_index is not UNSET:
            field_dict["block1_end_index"] = block1_end_index
        if block2_end_index is not UNSET:
            field_dict["block2_end_index"] = block2_end_index
        if block2_start_index is not UNSET:
            field_dict["block2_start_index"] = block2_start_index
        if end_indices is not UNSET:
            field_dict["end_indices"] = end_indices
        if mapping is not UNSET:
            field_dict["mapping"] = mapping
        if start_indices is not UNSET:
            field_dict["start_indices"] = start_indices

        return field_dict

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

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

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

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

        end_indices = cast(list[int], d.pop("end_indices", UNSET))

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

                mapping.append(mapping_item)

        start_indices = cast(list[int], d.pop("start_indices", UNSET))

        types_payroll_parse_result_sheet = cls(
            block1_end_index=block1_end_index,
            block2_end_index=block2_end_index,
            block2_start_index=block2_start_index,
            end_indices=end_indices,
            mapping=mapping,
            start_indices=start_indices,
        )

        types_payroll_parse_result_sheet.additional_properties = d
        return types_payroll_parse_result_sheet

    @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
