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 ..models.action_type import ActionType
from ..models.data_flow_type import DataFlowType
from ..types import UNSET, Unset

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


@_attrs_define
class NodeData:
    """
    Attributes:
        label (str):
        action_id (str):
        type_ (ActionType | None | Unset):
        updated_at (datetime.datetime | None | Unset):
        character_id (None | str | Unset):
        data_flow_type (DataFlowType | Unset):
        user_review_required (bool | Unset):  Default: False.
        user_review_done (bool | Unset):  Default: False.
        user_input_required (bool | Unset):  Default: False.
        user_input_done (bool | Unset):  Default: False.
        is_loop (bool | Unset):  Default: False.
        seperator (str | Unset):  Default: '|'.
        is_split (bool | Unset):  Default: False.
        file_split (bool | Unset):  Default: False.
        api_loop (bool | Unset):  Default: False.
        excel_loop (bool | Unset):  Default: False.
        header (bool | Unset):  Default: False.
        data_processing (bool | Unset):  Default: False.
        file_processing (bool | Unset):  Default: False.
        file_column_index (int | Unset):  Default: 0.
        instruction_column_index (int | Unset):  Default: 0.
        batches (int | Unset):  Default: 0.
        process_url_in_text (bool | Unset):  Default: True.
        process_attachment_url (bool | Unset):  Default: True.
        attachment_requested (int | Unset):  Default: 0.
        sleep_time (float | Unset): Seconds to sleep before executing the node action. Default: 0.0.
    """

    label: str
    action_id: str
    type_: ActionType | None | Unset = UNSET
    updated_at: datetime.datetime | None | Unset = UNSET
    character_id: None | str | Unset = UNSET
    data_flow_type: DataFlowType | Unset = UNSET
    user_review_required: bool | Unset = False
    user_review_done: bool | Unset = False
    user_input_required: bool | Unset = False
    user_input_done: bool | Unset = False
    is_loop: bool | Unset = False
    seperator: str | Unset = "|"
    is_split: bool | Unset = False
    file_split: bool | Unset = False
    api_loop: bool | Unset = False
    excel_loop: bool | Unset = False
    header: bool | Unset = False
    data_processing: bool | Unset = False
    file_processing: bool | Unset = False
    file_column_index: int | Unset = 0
    instruction_column_index: int | Unset = 0
    batches: int | Unset = 0
    process_url_in_text: bool | Unset = True
    process_attachment_url: bool | Unset = True
    attachment_requested: int | Unset = 0
    sleep_time: float | Unset = 0.0
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        action_id = self.action_id

        type_: None | str | Unset
        if isinstance(self.type_, Unset):
            type_ = UNSET
        elif isinstance(self.type_, ActionType):
            type_ = self.type_.value
        else:
            type_ = self.type_

        updated_at: None | str | Unset
        if isinstance(self.updated_at, Unset):
            updated_at = UNSET
        elif isinstance(self.updated_at, datetime.datetime):
            updated_at = self.updated_at.isoformat()
        else:
            updated_at = self.updated_at

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

        data_flow_type: str | Unset = UNSET
        if not isinstance(self.data_flow_type, Unset):
            data_flow_type = self.data_flow_type.value

        user_review_required = self.user_review_required

        user_review_done = self.user_review_done

        user_input_required = self.user_input_required

        user_input_done = self.user_input_done

        is_loop = self.is_loop

        seperator = self.seperator

        is_split = self.is_split

        file_split = self.file_split

        api_loop = self.api_loop

        excel_loop = self.excel_loop

        header = self.header

        data_processing = self.data_processing

        file_processing = self.file_processing

        file_column_index = self.file_column_index

        instruction_column_index = self.instruction_column_index

        batches = self.batches

        process_url_in_text = self.process_url_in_text

        process_attachment_url = self.process_attachment_url

        attachment_requested = self.attachment_requested

        sleep_time = self.sleep_time

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "label": label,
                "actionId": action_id,
            }
        )
        if type_ is not UNSET:
            field_dict["type"] = type_
        if updated_at is not UNSET:
            field_dict["updated_at"] = updated_at
        if character_id is not UNSET:
            field_dict["characterId"] = character_id
        if data_flow_type is not UNSET:
            field_dict["data_flow_type"] = data_flow_type
        if user_review_required is not UNSET:
            field_dict["user_review_required"] = user_review_required
        if user_review_done is not UNSET:
            field_dict["user_review_done"] = user_review_done
        if user_input_required is not UNSET:
            field_dict["user_input_required"] = user_input_required
        if user_input_done is not UNSET:
            field_dict["user_input_done"] = user_input_done
        if is_loop is not UNSET:
            field_dict["is_loop"] = is_loop
        if seperator is not UNSET:
            field_dict["seperator"] = seperator
        if is_split is not UNSET:
            field_dict["is_split"] = is_split
        if file_split is not UNSET:
            field_dict["file_split"] = file_split
        if api_loop is not UNSET:
            field_dict["api_loop"] = api_loop
        if excel_loop is not UNSET:
            field_dict["excel_loop"] = excel_loop
        if header is not UNSET:
            field_dict["header"] = header
        if data_processing is not UNSET:
            field_dict["data_processing"] = data_processing
        if file_processing is not UNSET:
            field_dict["file_processing"] = file_processing
        if file_column_index is not UNSET:
            field_dict["file_column_index"] = file_column_index
        if instruction_column_index is not UNSET:
            field_dict["instruction_column_index"] = instruction_column_index
        if batches is not UNSET:
            field_dict["batches"] = batches
        if process_url_in_text is not UNSET:
            field_dict["process_url_in_text"] = process_url_in_text
        if process_attachment_url is not UNSET:
            field_dict["process_attachment_url"] = process_attachment_url
        if attachment_requested is not UNSET:
            field_dict["attachment_requested"] = attachment_requested
        if sleep_time is not UNSET:
            field_dict["sleep_time"] = sleep_time

        return field_dict

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

        action_id = d.pop("actionId")

        def _parse_type_(data: object) -> ActionType | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                type_type_0 = ActionType(data)

                return type_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(ActionType | None | Unset, data)

        type_ = _parse_type_(d.pop("type", UNSET))

        def _parse_updated_at(data: object) -> datetime.datetime | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                updated_at_type_0 = isoparse(data)

                return updated_at_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(datetime.datetime | None | Unset, data)

        updated_at = _parse_updated_at(d.pop("updated_at", UNSET))

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

        character_id = _parse_character_id(d.pop("characterId", UNSET))

        _data_flow_type = d.pop("data_flow_type", UNSET)
        data_flow_type: DataFlowType | Unset
        if isinstance(_data_flow_type, Unset):
            data_flow_type = UNSET
        else:
            data_flow_type = DataFlowType(_data_flow_type)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        node_data = cls(
            label=label,
            action_id=action_id,
            type_=type_,
            updated_at=updated_at,
            character_id=character_id,
            data_flow_type=data_flow_type,
            user_review_required=user_review_required,
            user_review_done=user_review_done,
            user_input_required=user_input_required,
            user_input_done=user_input_done,
            is_loop=is_loop,
            seperator=seperator,
            is_split=is_split,
            file_split=file_split,
            api_loop=api_loop,
            excel_loop=excel_loop,
            header=header,
            data_processing=data_processing,
            file_processing=file_processing,
            file_column_index=file_column_index,
            instruction_column_index=instruction_column_index,
            batches=batches,
            process_url_in_text=process_url_in_text,
            process_attachment_url=process_attachment_url,
            attachment_requested=attachment_requested,
            sleep_time=sleep_time,
        )

        node_data.additional_properties = d
        return node_data

    @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
