from __future__ import annotations

import datetime
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 dateutil.parser import isoparse

from ..types import UNSET, Unset

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


@_attrs_define
class JobStatusSchema:
    """
    Attributes:
        field_id (str):
        user_id (str):
        status (str):
        weaviate_status (str):
        graphrag_status (str):
        created_at (datetime.datetime):
        updated_at (datetime.datetime):
        kb_id (None | str | Unset):
        tenant_id (None | str | Unset):
        uploaded_by_user_id (None | str | Unset):
        uploaded_by_email (None | str | Unset):
        collection_name (None | str | Unset):
        original_filename (None | str | Unset):
        s3_url (None | str | Unset):
        error_message (None | str | Unset):
    """

    field_id: str
    user_id: str
    status: str
    weaviate_status: str
    graphrag_status: str
    created_at: datetime.datetime
    updated_at: datetime.datetime
    kb_id: None | str | Unset = UNSET
    tenant_id: None | str | Unset = UNSET
    uploaded_by_user_id: None | str | Unset = UNSET
    uploaded_by_email: None | str | Unset = UNSET
    collection_name: None | str | Unset = UNSET
    original_filename: None | str | Unset = UNSET
    s3_url: None | str | Unset = UNSET
    error_message: None | str | 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

        user_id = self.user_id

        status = self.status

        weaviate_status = self.weaviate_status

        graphrag_status = self.graphrag_status

        created_at = self.created_at.isoformat()

        updated_at = self.updated_at.isoformat()

        kb_id: None | str | Unset
        if isinstance(self.kb_id, Unset):
            kb_id = UNSET
        else:
            kb_id = self.kb_id

        tenant_id: None | str | Unset
        if isinstance(self.tenant_id, Unset):
            tenant_id = UNSET
        else:
            tenant_id = self.tenant_id

        uploaded_by_user_id: None | str | Unset
        if isinstance(self.uploaded_by_user_id, Unset):
            uploaded_by_user_id = UNSET
        else:
            uploaded_by_user_id = self.uploaded_by_user_id

        uploaded_by_email: None | str | Unset
        if isinstance(self.uploaded_by_email, Unset):
            uploaded_by_email = UNSET
        else:
            uploaded_by_email = self.uploaded_by_email

        collection_name: None | str | Unset
        if isinstance(self.collection_name, Unset):
            collection_name = UNSET
        else:
            collection_name = self.collection_name

        original_filename: None | str | Unset
        if isinstance(self.original_filename, Unset):
            original_filename = UNSET
        else:
            original_filename = self.original_filename

        s3_url: None | str | Unset
        if isinstance(self.s3_url, Unset):
            s3_url = UNSET
        else:
            s3_url = self.s3_url

        error_message: None | str | Unset
        if isinstance(self.error_message, Unset):
            error_message = UNSET
        else:
            error_message = self.error_message

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "_id": field_id,
                "user_id": user_id,
                "status": status,
                "weaviate_status": weaviate_status,
                "graphrag_status": graphrag_status,
                "created_at": created_at,
                "updated_at": updated_at,
            }
        )
        if kb_id is not UNSET:
            field_dict["kb_id"] = kb_id
        if tenant_id is not UNSET:
            field_dict["tenant_id"] = tenant_id
        if uploaded_by_user_id is not UNSET:
            field_dict["uploaded_by_user_id"] = uploaded_by_user_id
        if uploaded_by_email is not UNSET:
            field_dict["uploaded_by_email"] = uploaded_by_email
        if collection_name is not UNSET:
            field_dict["collection_name"] = collection_name
        if original_filename is not UNSET:
            field_dict["original_filename"] = original_filename
        if s3_url is not UNSET:
            field_dict["s3_url"] = s3_url
        if error_message is not UNSET:
            field_dict["error_message"] = error_message

        return field_dict

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

        user_id = d.pop("user_id")

        status = d.pop("status")

        weaviate_status = d.pop("weaviate_status")

        graphrag_status = d.pop("graphrag_status")

        created_at = isoparse(d.pop("created_at"))

        updated_at = isoparse(d.pop("updated_at"))

        def _parse_kb_id(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        kb_id = _parse_kb_id(d.pop("kb_id", UNSET))

        def _parse_tenant_id(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        tenant_id = _parse_tenant_id(d.pop("tenant_id", UNSET))

        def _parse_uploaded_by_user_id(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        uploaded_by_user_id = _parse_uploaded_by_user_id(d.pop("uploaded_by_user_id", UNSET))

        def _parse_uploaded_by_email(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        uploaded_by_email = _parse_uploaded_by_email(d.pop("uploaded_by_email", UNSET))

        def _parse_collection_name(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        collection_name = _parse_collection_name(d.pop("collection_name", UNSET))

        def _parse_original_filename(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        original_filename = _parse_original_filename(d.pop("original_filename", UNSET))

        def _parse_s3_url(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        s3_url = _parse_s3_url(d.pop("s3_url", UNSET))

        def _parse_error_message(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        error_message = _parse_error_message(d.pop("error_message", UNSET))

        job_status_schema = cls(
            field_id=field_id,
            user_id=user_id,
            status=status,
            weaviate_status=weaviate_status,
            graphrag_status=graphrag_status,
            created_at=created_at,
            updated_at=updated_at,
            kb_id=kb_id,
            tenant_id=tenant_id,
            uploaded_by_user_id=uploaded_by_user_id,
            uploaded_by_email=uploaded_by_email,
            collection_name=collection_name,
            original_filename=original_filename,
            s3_url=s3_url,
            error_message=error_message,
        )

        job_status_schema.additional_properties = d
        return job_status_schema

    @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
