from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar, cast

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

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


@_attrs_define
class Metadata:
    """
    Attributes:
        key (str | Unset):
        value (str | Unset):
        expression (str | Unset):
        class_ (str | Unset):
        tags (list[float] | Unset):
        pages (list[float] | Unset):
        ref (str | Unset):
        confidence (float | Unset):
    """

    key: str | Unset = UNSET
    value: str | Unset = UNSET
    expression: str | Unset = UNSET
    class_: str | Unset = UNSET
    tags: list[float] | Unset = UNSET
    pages: list[float] | Unset = UNSET
    ref: str | Unset = UNSET
    confidence: float | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        value = self.value

        expression = self.expression

        class_ = self.class_

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

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

        ref = self.ref

        confidence = self.confidence

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if key is not UNSET:
            field_dict["key"] = key
        if value is not UNSET:
            field_dict["value"] = value
        if expression is not UNSET:
            field_dict["expression"] = expression
        if class_ is not UNSET:
            field_dict["class"] = class_
        if tags is not UNSET:
            field_dict["tags"] = tags
        if pages is not UNSET:
            field_dict["pages"] = pages
        if ref is not UNSET:
            field_dict["ref"] = ref
        if confidence is not UNSET:
            field_dict["confidence"] = confidence

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        key = d.pop("key", UNSET)

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

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

        class_ = d.pop("class", UNSET)

        tags = cast(list[float], d.pop("tags", UNSET))

        pages = cast(list[float], d.pop("pages", UNSET))

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

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

        metadata = cls(
            key=key,
            value=value,
            expression=expression,
            class_=class_,
            tags=tags,
            pages=pages,
            ref=ref,
            confidence=confidence,
        )

        metadata.additional_properties = d
        return metadata

    @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
