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.document import Document
    from ..models.document_get_response_200_words_item import DocumentGetResponse200WordsItem
    from ..models.tpa_statement import TpaStatement


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


@_attrs_define
class DocumentGetResponse200:
    """
    Attributes:
        success (bool | Unset):
        doc (Document | Unset):
        statement (TpaStatement | Unset):
        pages (list[str] | Unset): Presigned URLs for pages (if presigned=true)
        download_url (str | Unset): Presigned download URL (if presigned=true)
        words_url (str | Unset): Presigned words index URL (if presigned=true)
        words (list[DocumentGetResponse200WordsItem] | Unset): Word index data
    """

    success: bool | Unset = UNSET
    doc: Document | Unset = UNSET
    statement: TpaStatement | Unset = UNSET
    pages: list[str] | Unset = UNSET
    download_url: str | Unset = UNSET
    words_url: str | Unset = UNSET
    words: list[DocumentGetResponse200WordsItem] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

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

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

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

        download_url = self.download_url

        words_url = self.words_url

        words: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.words, Unset):
            words = []
            for words_item_data in self.words:
                words_item = words_item_data.to_dict()
                words.append(words_item)

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if success is not UNSET:
            field_dict["success"] = success
        if doc is not UNSET:
            field_dict["doc"] = doc
        if statement is not UNSET:
            field_dict["statement"] = statement
        if pages is not UNSET:
            field_dict["pages"] = pages
        if download_url is not UNSET:
            field_dict["downloadUrl"] = download_url
        if words_url is not UNSET:
            field_dict["wordsUrl"] = words_url
        if words is not UNSET:
            field_dict["words"] = words

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.document import Document
        from ..models.document_get_response_200_words_item import DocumentGetResponse200WordsItem
        from ..models.tpa_statement import TpaStatement

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

        _doc = d.pop("doc", UNSET)
        doc: Document | Unset
        if isinstance(_doc, Unset):
            doc = UNSET
        else:
            doc = Document.from_dict(_doc)

        _statement = d.pop("statement", UNSET)
        statement: TpaStatement | Unset
        if isinstance(_statement, Unset):
            statement = UNSET
        else:
            statement = TpaStatement.from_dict(_statement)

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

        download_url = d.pop("downloadUrl", UNSET)

        words_url = d.pop("wordsUrl", UNSET)

        _words = d.pop("words", UNSET)
        words: list[DocumentGetResponse200WordsItem] | Unset = UNSET
        if _words is not UNSET:
            words = []
            for words_item_data in _words:
                words_item = DocumentGetResponse200WordsItem.from_dict(words_item_data)

                words.append(words_item)

        document_get_response_200 = cls(
            success=success,
            doc=doc,
            statement=statement,
            pages=pages,
            download_url=download_url,
            words_url=words_url,
            words=words,
        )

        document_get_response_200.additional_properties = d
        return document_get_response_200

    @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
